开发者

json parsing in javascript for PhoneGap app

in my phone gap, when the button is clicked it hi开发者_开发百科ts an api and in return i am getting a json array as response as follows

{"Status":[{ "Id": "46", "Username": "guru",image:"http://xxxxx/xxxxxxxxxx//Tulips.jpg" }]} 

i have stored this value in an var. Now i want to parse this response and i want to store the Id value and Username values and also the image in another var. How to do this

i tried by the following line

var data = JSON.parse(my_JSON_object);
        var  Username= data.Status.Itemlist[0].Username;
                    alert(UserName);

where in my_JSON_object i have stored the json array value.i got the username but the image is not displayed only the url gets displayed pls hlp me


If the data is exactly the same as you have shown here:

var data = JSON.parse(my_JSON_object);

var id = data.Status[0].Id;
var name = data.Status[0].Username;


your missing the quotes on the "image" object part of your JSON.

your JSON:

    {"Status":[{ "Id": "46", "Username": "guru",image:"http://xxxxx/xxxxxxxxxx//Tulips.jpg" }]}

Corrected JSON:

    {"Status":[{ "Id": "46", "Username": "guru","image":"http://xxxxx/xxxxxxxxxx//Tulips.jpg" }]}
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜