我正在使用钛来开发Android应用程序。我想从json对象中删除一些数据。我的json对象如下:
{"feeds":
[
{"username":"abc","user":"abc","feed":{"description":"dss","id":660,"user_id":1}},
{"username":"bcd","user":"bcd","feed":{"description":"dddd","id":659,"user_id":1}}
]
}
用于接收我使用以下代码的json对象
var json = this.responseText;
var json = JSON.parse(json);
json.feeds.splice(0,1);
alert(json.feeds[0]);
我想使用JavaScript从json.feeds[0]
等json对象中删除特定数据。我可以访问json.feeds[0]
但无法删除。有没有办法使用JavaScript从json对象中删除该数据?
答案 0 :(得分:3)
答案 1 :(得分:3)
您正在使用splice从javascript数组中正确删除元素:
json.feeds.splice(0,1)
使用您提供的代码,它将如下所示:
(function(){
var json = {
"feeds": [
{"username":"abc","user":"abc","feed":{"description":"dss","id":660,"user_id":1}},
{"username":"bcd","user":"bcd","feed":{"description":"dddd","id":659,"user_id":1}}
]
};
json.feeds.splice(0,1);
console.log(json.feeds); // just to check that "feeds" contains only a single element
})();