开发者

problem in json parsing in android app

in my app when i hit an url i am getting a return data as an json array. it is as follows

{"Status":[{ "img_path": "http://xxxxxxxxxxxxxx.com/images/thumb140/1316145577.jpg", 
             "img_path": "http://xxxxxxxxxxxxxx.com/images/thumb140/1316146270.jpg", 
             "img_path": "http://xxxxxxxxxxxxxx.com/images/thumb140/1316146开发者_运维技巧473.jpg", 
             "img_path": "http://xxxxxxxxxxxxxx.com/images/thumb140/1316147003.jpg" } ]} 

From the above result i am trying to parse out the urls and i am trying to store it in an array list. Following is my code

 try{
        JSONArray get_post_status = json.getJSONArray("Status");
        for (int i = 0; i < get_post_status.length(); i++) {
        JSONObject e = get_post_status.getJSONObject(i);
        if(e.equals("img_path"))
        {
            Get_post_image_array.add(e.getString("img_path"));
        }
        }

But in my arraylist i am getting only the last url from the result. How to get all the urls in the arraylist.

Pls help me.......


The returned JSON is invalid.

Shortening the data, looking only at the structure:

{
    "Status":
        [
            {
                "img_path": "a", 
                "img_path": "b", 
                "img_path": "c", 
                "img_path": "d"
            }
        ]
}

We can see that the array (enclosed in []) only contains one element; the object enclosed by {}. This object has several instances of the same key, "img_path". This is not valid. Your parser apparently ends up with keeping only the last instance of it.

The JSON ought to look more like this:

{
    "Status":
        [
            "a", 
            "b", 
            "c", 
            "d"
        ]
}


Your JSON is invalid.

{"Status": [ {"img_path": "blah, blah"}, {"img_path": "blah2, blah3"}]}

is what you want. Essentially, you were setting the same key in an object over and over, not creating a list of objects.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜