您好,有没有办法可以将此 json 对象转换为两个数组?我已经尝试了下面的代码,它工作正常,但是我无法将 json 对象转换为两个数组,一个名为“id”,另一个数组名为“name”。我该怎么办。这就是我已经走了多远
int[] id= {};
String[] names={};
myfunction = new myFunctions();
json = userfunction.petitions();
try {
if (json.get(KEY_SUCCESS) != null) {
String rs = json.getString(KEY_SUCCESS);
if (Integer.parseInt(rs) == 1) {
inserting ids into id array here....
inserting names into names array here..
}
}
} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
json对象是
10-25 02:08:54.325: E/JSON(406): {"success":1,"petitions":[{"id":"1","name":"Has Jennifer Musisi done great work for Kampala","timestamp":"2013-10-24 14:32:58"},{"id":"2","name":"Do lecturers deserve 100% salary increase","timestamp":"2013-10-24 14:32:58"},{"id":"3","name":"Olara Otunu should get married","timestamp":"2013-10-24 14:33:53"},{"id":"4","name":"Teachers deserve 30 not 20 salary rise","timestamp":"2013-10-24 14:33:53"},{"id":"5","name":"Prostitution should be banned","timestamp":"2013-10-24 14:33:53"}]}