0

in my phone gap, when the button is clicked it hits 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

2 Answers 2

1

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;
Sign up to request clarification or add additional context in comments.

2 Comments

i tried your answer but i got an error in my logcat as follows ERROR/Web Console(3230): TypeError: Result of expression 'my_JSON_object.Status' [undefined] is not an object. at file:///android_asset/www/index.html:26
can u pls say how to display the images
0

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" }]}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.