我是android的新手。我的字符串看起来像这样:
String json={"time":"12.00", "data":"25/01/2014","users":
[
{"id":1231,"title":"hello","url":"world"},
{"id":7656,"title":"hello","url":"world"},
{"id":3356,"title":"hello","url":"world"}
],"is_valid":false}
现在我需要删除第二个用户JSONObject:
{"id":7656,"title":"hello","url":"world"}
所以我尝试了以下内容:
JSONObject json=new JSONObject(json);
JSONArray users=json.getJSONArray("users");
users.remove(1);
json.put("users",users);
String new_json=json.toString();
但不幸的是,每当我使用users.remove(1)时,应用程序都会强制关闭。方法请有人帮帮我。
删除对象后我需要关注字符串:
String new_json=
tring json={"time":"12.00", "data":"25/01/2014","users":
[
{"id":1231,"title":"hello","url":"world"},
{"id":3356,"title":"hello","url":"world"}
],"is_valid":false}
感谢所有伟大的程序员