Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/docker/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 在Android中使用Json_Java_Android_Json - Fatal编程技术网

Java 在Android中使用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

我在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": "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