sbh
@sbh

Как распарсить и вывести json данные с помощью jquery?

Вот кусок данных которые нужно распарсить и вывести на экран:

{"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


в коде я делаю во так:
success: function (response) {
	var parced_response = $.parseJSON(response);
	for (var i in parced_response) 
	{
		alert(parced_response.data.images.url);
	}
}


получаю ошибку
parced_response.data.images is undefined
  • Вопрос задан
  • 599 просмотров
Решения вопроса 1
Stalker_RED
@Stalker_RED
У вас же в data находится массив, и только в нем уже user.
parced_response.data[0].user.id
Ответ написан
Пригласить эксперта
Ответы на вопрос 1
vanyahuk
@vanyahuk
var obj  = JSON.parse(response)
for( var prop in obj.data )
{
alert(obj.data[prop])
}
Ответ написан
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Похожие вопросы