S
S
sbh2017-05-11 04:17:52
JavaScript
sbh, 2017-05-11 04:17:52

How to parse and display json data using jquery?

Here is a piece of data that needs to be parsed and displayed on the screen:

{"pagination": {}, "data": [{"id": "1510850986956435454_196691920", "user": {"id": "196691920", "full_name": "", "profile_picture": "https://scontent.cdninstagram.com/t51.2885-19/s150x150/18253176_737767466384957_4591365669156552704_a.jpg", "username": "proto"}, "images": {"thumbnail": {"width": 150, "height": 150, "url": "https://scontent.cdninstagram.com/t51.2885-15/s150x150/e35/18382067_1857240057869438_4539565863895826432_n.jpg"}, "low_resolution": {"width": 320, "height": 320, "url": "https://scontent.cdninstagram.com/t51.2885-15/s320x320/e35/18382067_1857240057869438_4539565863895826432_n.jpg"}, "standard_resolution": {"width": 320, "height": 320, "url": "https://scontent.cdninstagram.com/t51.2885-15/s320x320/e35/18382067_1857240057869438_4539565863895826432_n.jpg"}}, "created_time": "1494327494", "caption": {"id": "17868581308102795", "text": "#coffee", "created_time": "1494327494", "from": {"id": "196691920", "full_name": "", "profile_picture": "https://scontent.cdninstagram.com/t51.2885-19/s150x150/18253176_737767466384957_4591365669156552704_a.jpg", "username": "proto"}}, "user_has_liked": false, "likes": {"count": 0}, "tags": ["coffee"], "filter": "Normal", "comments": {"count": 0}, "type": "image", "link": "https://www.instagram.com/p/BT3nvfCFi_-/", "location": null, "attribution": null, "users_in_photo": []}, {"id": "1510850848292767739_196691920", "user": {"id": "196691920", "full_name": "", "profile_picture": "https://scontent.cdninstagram.com/t51.2885-19/s150x150/18253176_737767466384957_4591365669156552704_a.jpg", "username": "proto"}, "images": {"thumbnail": {"width": 150, "height": 150, "url": "https://scontent.cdninstagram.com/t51.2885-15/s150x150/e35/18299712_229253330894650_8290691365650563072_n.jpg"}, "low_resolution": {"width": 320, "height": 320, "url": "https://scontent.cdninstagram.com/t51.2885-15/s320x320/e35/18299712_229253330894650_8290691365650563072_n.jpg"}, "standard_resolution": {"width": 640, "height": 640, "url": "https://scontent.cdninstagram.com/t51.2885-15/s640x640/sh0.08/e35/18299712_229253330894650_8290691365650563072_n.jpg"}}, "created_time": "1494327477", "caption": {"id": "17880623473011720", "text": "#coffee", "created_time": "1494327477", "from": {"id": "196691920", "full_name": "", "profile_picture": "https://scontent.cdninstagram.com/t51.2885-19/s150x150/18253176_737767466384957_4591365669156552704_a.jpg", "username": "proto"}}, "user_has_liked": false, "likes": {"count": 0}, "tags": ["coffee"], "filter": "Normal", "comments": {"count": 0}, "type": "image", "link": "https://www.instagram.com/p/BT3ntd5Fof7/", "location": null, "attribution": null, "users_in_photo": []}, {"id": "1510850723881203332_196691920", "user": {"id": "196691920", "full_name": "", "profile_picture": "https://scontent.cdninstagram.com/t51.2885-19/s150x150/18253176_737767466384957_4591365669156552704_a.jpg", "username": "proto"}, "images": {"thumbnail": {"width": 150, "height": 150, "url": "https://scontent.cdninstagram.com/t51.2885-15/s150x150/e35/c70.0.179.179/18300109_1375661945857335_2544168609869987840_n.jpg"}, "low_resolution": {"width": 320, "height": 179, "url": "https://scontent.cdninstagram.com/t51.2885-15


in code i do like this:
success: function (response) {
  var parced_response = $.parseJSON(response);
  for (var i in parced_response) 
  {
    alert(parced_response.data.images.url);
  }
}


I get the error
parced_response.data.images is undefined

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
Stalker_RED, 2017-05-11
@sbh

You have an array in data, and only in it is user.
parced_response.data[0].user.id

V
Vanya Huk, 2017-05-11
@vanyahuk

var obj  = JSON.parse(response)
for( var prop in obj.data )
{
alert(obj.data[prop])
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question