JSON Parsing VK API
Имею следующий JSON ответ от сервера:
{"response":
{"count":30,
"items":[
{
"id":54,"from_id":631614272,"owner_id":631614272,"date":1612547653,"post_type":"post","text":"Тест.запись -s","can_edit":1,"can_delete":1,"can_pin":1,"can_archive":true,"is_archived":false,"post_source":{"type":"api"},"comments":{"count":0,"can_post":1,"groups_can_post":true},"likes":{"count":0,"user_likes":0,"can_like":1,"can_publish":1},"reposts":{"count":0,"wall_count":0,"mail_count":0,"user_reposted":0}},
{"id":53,"from_id":631614272,"owner_id":631614272,"date":1612547531,"post_type":"post","text":"Тест.запись -s","can_edit":1,"can_delete":1,"can_pin":1,"can_archive":true,"is_archived":false,"post_source":{"type":"api"},"comments":{"count":0,"can_post":1,"groups_can_post":true},"likes":{"count":0,"user_likes":0,"can_like":1,"can_publish":1},"reposts":{"count":0,"wall_count":0,"mail_count":0,"user_reposted":0}}
Как мне его проще распарсить, чтобы получить только id-значения каждого из item, которые потом легко будет поместить в массив чисел?
Ответы (1 шт):
Автор решения: sonicJs
→ Ссылка
var arr = [];
var json = {"response": {"count":30, "items":[
{"id":54,"from_id":631614272,"owner_id":631614272,"date":1612547653,
"post_type":"post","text":"Тест.запись -s",
"can_edit":1,"can_delete":1,"can_pin":1,"can_archive":true,"is_archived":false,
"post_source":{"type":"api"},"comments":{"count":0,"can_post":1,"groups_can_post":true},
"likes":{"count":0,"user_likes":0,"can_like":1,"can_publish":1},
"reposts":{"count":0,"wall_count":0,"mail_count":0,"user_reposted":0}},
{"id":53,"from_id":631614272,"owner_id":631614272,"date":1612547531,
"post_type":"post","text":"Тест.запись -s",
"can_edit":1,"can_delete":1,"can_pin":1,"can_archive":true,"is_archived":false,
"post_source":{"type":"api"},"comments":{"count":0,"can_post":1,"groups_can_post":true},
"likes":{"count":0,"user_likes":0,"can_like":1,"can_publish":1},
"reposts":{"count":0,"wall_count":0,"mail_count":0,"user_reposted":0}};
json.response.items.map((result) => { arr.push(result) });
console.log(arr);