Java 在Android中使用Json
我在Android中使用Json,这是我收到的Json:Java 在Android中使用Json,java,android,json,Java,Android,Json,我在Android中使用Json,这是我收到的Json: [ { "0": "5", "1": "CorpoSA", "2": "CorpoSA", "3": "http://162.243.229.85/images/CORPO%20SA%20logo.jpg", "id": "5", "title": "CorpoSA", "description": "Corpo
[
{
"0": "5",
"1": "CorpoSA",
"2": "CorpoSA",
"3": "http://162.243.229.85/images/CORPO%20SA%20logo.jpg",
"id": "5",
"title": "CorpoSA",
"description": "CorpoSA",
"img_url": "http://162.243.229.85/images/CORPO%20SA%20logo.jpg"
},
{
"0": "6",
"1": "CorpoSA2",
"2": "CorpoSA2",
"3": "http://162.243.229.85/images/home.jpg",
"id": "6",
"title": "CorpoSA2",
"description": "CorpoSA2",
"img_url": "http://162.243.229.85/images/home.jpg"
}
]
我有一个名为result的字符串,但我不知道如何提取id、title、description和url,以及如何保存在数据库中
当我使用:
JSONObject json = new JSONObject(result);
然后
json.getJSONObject("id");
这不起作用,请有人帮帮我试试这个
try{
JSONArray jsonArray = new JSONArray(result);
// looping through All jsonObject
for (int i = 0; i < jsonArray.length(); i++) {
JSONObject jsonObject = jsonArray.getJSONObject(i);
String id = jsonObject.getString("id");
String title = jsonObject.getString("title");
String description = jsonObject.getString("description");
String img_url = jsonObject.getString("img_url");
}
} catch (JSONException e) {
e.printStackTrace();
}
试试看{
JSONArray JSONArray=新JSONArray(结果);
//循环遍历所有jsonObject
for(int i=0;i
为什么要使用JSONObject json=new-JSONObject(result)代码>?另外,您希望看到什么json.getJSONObject(“id”)代码>返回<代码>5
或6
?