JS receiving enumMap in json see fields as undefined - javascript

I have REST ws which send json. Inside json there is enumMap (from java) and when I recieve json from REST, it looks like this:
{
map:{
KEY1:VALUE1,
KEY2:VALUE2}
}
when i try to do:
var something = map.KEY1;
console.log(something);
i see that something is undefined but when i do
console.log(map.KEY1);
than i see VALUE1
I don't see why it is not working. I tried many different set ups but in every one of them behaviour is the same or exception was thrown. Any ideas ?

Related

Parse JSON data from a website with HTTP request with javascript

I've used package sniffer to get a specific endpoint, which gave me a direct JSON url. Now I want to get for all usernames from this JSON format.For eg. it goes like this:
{"node":{"id":"1428809588","username":"kafeterijabg","full_name":"\u041a\u0430\u0444\u0435\u0442\u0435\u0440\u0438\u0458\u0430\u00ae","profile_pic_url":"https://instagram.fbeg5-1.fna.fbcdn.net/vp/65f96409e2a6c5b9b72cda956aa0dfea/5E638B5F/t51.2885-19/s150x150/64620072_350924665805634_2914908438809018368_n.jpg?_nc_ht=instagram.fbeg5-1.fna.fbcdn.net","is_private":false,"is_verified":false,"followed_by_viewer":true,"requested_by_viewer":false,"reel":{"id":"1428809588","expiring_at":1572193230,"has_pride_media":false,"latest_reel_media":1572095740,"seen":1572031349,"owner":{"__typename":"GraphUser","id":"1428809588","profile_pic_url":"https://instagram.fbeg5-1.fna.fbcdn.net/vp/65f96409e2a6c5b9b72cda956aa0dfea/5E638B5F/t51.2885-19/s150x150/64620072_350924665805634_2914908438809018368_n.jpg?_nc_ht=instagram.fbeg5-1.fna.fbcdn.net","username":"kafeterijabg"}}}}
I've tried sending requests and parsing it to console but I'm getting "undefined".
function Get(yourUrl){
var Httpreq = new XMLHttpRequest();
Httpreq.open("GET",yourUrl,false);
Httpreq.send(null);
return Httpreq.responseText;
}
var json_obj = JSON.parse(Get(MYURL));
console.log(json_obj.username);
I've never done anything similar before.
EDIT1:
It seems like I was using the wrong endpoint.But when I just try to get the output of the request without parsing it I'm getting only first two lines of It, even tho when I open the endpoint in browser I'm seeing all of it.
This is what I'm getting:
{"data":{"user":{"edge_follow":{"count":377,"page_info":{"has_next_page":false,"end_cursor":null},"edges":[]}}},"status":"ok"}
And here is what I expected to get.
{"data":{"user":{"edge_follow":{"count":377,"page_info":{"has_next_page":true,"end_cursor":"QVFBd2J1MzJKakRoNXI3bzVqR1hTYkRYRjJ0TGJrNjJxeFVnRmVsc0JwczZLR1d3VXloZDA4NXFiUFV6dXU4RlRfck93M0J5Z1ZINVdieEtwREVmWFZNaA=="},"edges":[{"node":{"id":"8752655712","username":"dragibravo","full_name":"Dragi Bravo \u00a9","profile_pic_url":"https://instagram.fbeg5-1.fna.fbcdn.net/vp/5f53d36c1e430cbd5453478159c0a780/5E4CE6DD/t51.2885-19/s150x150/44656034_343135116439319_1392780490192191488_n.jpg?_nc_ht=instagram.fbeg5-1.fna.fbcdn.net","is_private":false,"is_verified":false,"followed_by_viewer":true,"requested_by_viewer":false,"reel":{"id":"8752655712","expiring_at":1572210555,"has_pride_media":false,"latest_reel_media":1572123916,"seen":1572085057,"owner":{"__typename":"GraphUser","id":"8752655712","profile_pic_url":"https://instagram.fbeg5-1.fna.fbcdn.net/vp/5f53d36c1e430cbd5453478159c0a780/5E4CE6DD/t51.2885-19/s150x150/44656034_343135116439319_1392780490192191488_n.jpg?_nc_ht=instagram.fbeg5-1.fna.fbcdn.net","username":"dragibravo"}}}},{"node":{"id":"21396562691","username":"dete_devedesetih","full_name":"detedevedesetih","profile_pic_url":"https://instagram.fbeg5-1.fna.fbcdn.net/vp/88d2c2221aaa75ca2ea16ab32d0f1578/5E42CEE5/t51.2885-19/s150x150/69694071_2580132948676320_8436138521869156352_n.jpg?_nc_ht=instagram.fbeg5-1.fna.fbcdn.net","is_private":false,"is_verified":false,"followed_by_viewer":true,"requested_by_viewer":false,"reel":{"id":"21396562691","expiring_at":1572210555,"has_pride_media":false,"latest_reel_media":1572123552,"seen":null,"owner":{"__typename":"GraphUser","id":"21396562691","profile_pic_url":"https://instagram.fbeg5-1.fna.fbcdn.net/vp/88d2c2221aaa75ca2ea16ab32d0f1578/5E42CEE5/t51.2885-19/s150x150/69694071_2580132948676320_8436138521869156352_n.jpg?_nc_ht=instagram.fbeg5-1.fna.fbcdn.net","username":"dete_devedesetih"}}}},{"node":{"id":"14659853","username":"brittanya187","full_name":"Brittanya Razavi","profile_pic_url":"https://instagram.fbeg5-1.fna.fbcdn.net/vp/f611badd19896aad1280c5743b4692d5/5E5907C2/t51.2885-19/s150x150/42002550_2204067873162229_8645854606632419328_n.jpg?_nc_ht=instagram.fbeg5-1.fna.fbcdn.net","is_private":false,"is_verified":true,"followed_by_viewer":true,"requested_by_viewer":false,"reel":{"id":"14659853","expiring_at":1572210555,"has_pride_media":false,"latest_reel_media":1572121817,"seen":1572039263,"owner":{"__typename":"GraphUser","id":"14659853","profile_pic_url":"https://instagram.fbeg5-1.fna.fbcdn.net/vp/f611badd19896aad1280c5743b4692d5/5E5907C2/t51.2885-19/s150x150/42002550_2204067873162229_8645854606632419328_n.jpg?_nc_ht=instagram.fbeg5-1.fna.fbcdn.net","username":"brittanya187"}}}},{"node":{"id":"1465895116","username":"britnibrid","full_name":"neispavana lepotica","profile_pic_url":"https://instagram.fbeg5-1.fna.fbcdn.net/vp/ce45b2702afa309ca3c581dbd99ba68f/5E5A1E14/t51.2885-19/s150x150/44828900_327180521439297_1922646860288229376_n.jpg?_nc_ht=instagram.fbeg5-1.fna.fbcdn.net","is_private":false,"is_verified":false,"followed_by_viewer":true,"requested_by_viewer":false,"reel":{"id":"1465895116","expiring_at":1572210555,"has_pride_media":false,"latest_reel_media":0,"seen":null,"owner":{"__typename":"GraphUser","id":"1465895116","profile_pic_url":"https://instagram.fbeg5-1.fna.fbcdn.net/vp/ce45b2702afa309ca3c581dbd99ba68f/5E5A1E14/t51.2885-19/s150x150/44828900_327180521439297_1922646860288229376_n.jpg?_nc_ht=instagram.fbeg5-1.fna.fbcdn.net","username":"britnibrid"}}}},{"node":{"id":"1428809588","username":"kafeterijabg","full_name":"\u041a\u0430\u0444\u0435\u0442\u0435\u0440\u0438\u0458\u0430\u00ae","profile_pic_url":"https://instagram.fbeg5-1.fna.fbcdn.net/vp/65f96409e2a6c5b9b72cda956aa0dfea/5E638B5F/t51.2885-19/s150x150/64620072_350924665805634_2914908438809018368_n.jpg?_nc_ht=instagram.fbeg5-1.fna.fbcdn.net","is_private":false,"is_verified":false,"followed_by_viewer":true,"requested_by_viewer":false,"reel":{"id":"1428809588","expiring_at":1572210555,"has_pride_media":false,"latest_reel_media":1572107760,"seen":1572107760,"owner":{"__typename":"GraphUser","id":"1428809588","profile_pic_url":"https://instagram.fbeg5-1.fna.fbcdn.net/vp/65f96409e2a6c5b9b72cda956aa0dfea/5E638B5F/t51.2885-19/s150x150/64620072_350924665805634_2914908438809018368_n.jpg?_nc_ht=instagram.fbeg5-1.fna.fbcdn.net","username":"kafeterijabg"}}}},{"node":{"id":"13795435410","username":"jacobs_rs","full_name":"JacobsSrbija","profile_pic_url":"https://instagram.fbeg5-1.fna.fbcdn.net/vp/4363dbdcf8e8a94bc65968dd4907ff60/5E64F5DB/t51.2885-19/s150x150/60911497_2333358360317600_4108961307611365376_n.jpg?_nc_ht=instagram.fbeg5-1.fna.fbcdn.net","is_private":false,"is_verified":false,"followed_by_viewer":true,"requested_by_viewer":false,"reel":{"id":"13795435410","expiring_at":1572210555,"has_pride_media":false,"latest_reel_media":1572081948,"seen":1572081948,"owner":{"__typename":"GraphUser","id":"13795435410","profile_pic_url":"https://instagram.fbeg5-1.fna.fbcdn.net/vp/4363dbdcf8e8a94bc65968dd4907ff60/5E64F5DB/t51.2885-19/s150x150/60911497_2333358360317600_4108961307611365376_n.jpg?_nc_ht=instagram.fbeg5-1.fna.fbcdn.net","username":"jacobs_rs"}}}},{"node":{"id":"6706638255","username":"apartment_a6_kopaonik","full_name":"Apartment A6 Kopaonik \u00ae","profile_pic_url":"https://instagram.fbeg5-1.fna.fbcdn.net/vp/db9d49897114fb812add6b89f60198da/5E54AB81/t51.2885-19/s150x150/45378715_351931902032023_3560095462486704128_n.jpg?_nc_ht=instagram.fbeg5-1.fna.fbcdn.net","is_private":false,"is_verified":false,"followed_by_viewer":true,"requested_by_viewer":false,"reel":{"id":"6706638255","expiring_at":1572210555,"has_pride_media":false,"latest_reel_media":0,"seen":1572023751,"owner":{"__typename":"GraphUser","id":"6706638255","profile_pic_url":"https://instagram.fbeg5-1.fna.fbcdn.net/vp/db9d49897114fb812add6b89f60198da/5E54AB81/t51.2885-19/s150x150/45378715_351931902032023_3560095462486704128_n.jpg?_nc_ht=instagram.fbeg5-1.fna.fbcdn.net","username":"apartment_a6_kopaonik"}}}},{"node":{"id":"21433171875","username":"dugestaze_svilajnac","full_name":"DUGE STAZE","profile_pic_url":"https://instagram.fbeg5-1.fna.fbcdn.net/vp/d5e220b083bfb4432cd6f4dda3a81ba7/5E47E625/t51.2885-19/s150x150/71523182_308405693359685_2542825728215351296_n.jpg?_nc_ht=instagram.fbeg5-1.fna.fbcdn.net","is_private":false,"is_verified":false,"followed_by_viewer":true,"requested_by_viewer":false,"reel":{"id":"21433171875","expiring_at":1572210555,"has_pride_media":false,"latest_reel_media":0,"seen":null,"owner":{"__typename":"GraphUser","id":"21433171875","profile_pic_url":"https://instagram.fbeg5-1.fna.fbcdn.net/vp/d5e220b083bfb4432cd6f4dda3a81ba7/5E47E625/t51.2885-19/s150x150/71523182_308405693359685_2542825728215351296_n.jpg?_nc_ht=instagram.fbeg5-1.fna.fbcdn.net","username":"dugestaze_svilajnac"}}}},{"node":{"id":"280846376","username":"dekstroza","full_name":"dekstroza","profile_pic_url":"https://instagram.fbeg5-1.fna.fbcdn.net/vp/838e15717ddeba3ff12d82657f3fa30e/5E5F3CCB/t51.2885-19/s150x150/70473686_396716634369751_3090030692306780160_n.jpg?_nc_ht=instagram.fbeg5-1.fna.fbcdn.net","is_private":false,"is_verified":false,"followed_by_viewer":true,"requested_by_viewer":false,"reel":{"id":"280846376","expiring_at":1572210555,"has_pride_media":false,"latest_reel_media":1572101572,"seen":1572101572,"owner":{"__typename":"GraphUser","id":"280846376","profile_pic_url":"https://instagram.fbeg5-1.fna.fbcdn.net/vp/838e15717ddeba3ff12d82657f3fa30e/5E5F3CCB/t51.2885-19/s150x150/70473686_396716634369751_3090030692306780160_n.jpg?_nc_ht=instagram.fbeg5-1.fna.fbcdn.net","username":"dekstroza"}}}},{"node":{"id":"6619361585","username":"ozbiljne_teme","full_name":"Ozbiljne Teme","profile_pic_url":"https://instagram.fbeg5-1.fna.fbcdn.net/vp/e56294e9abfe45f7c2ae2de54d208557/5E50CBDA/t51.2885-19/s150x150/53740023_372495643602512_1074420510437146624_n.jpg?_nc_ht=instagram.fbeg5-1.fna.fbcdn.net","is_private":false,"is_verified":false,"followed_by_viewer":true,"requested_by_viewer":false,"reel":{"id":"6619361585","expiring_at":1572210555,"has_pride_media":false,"latest_reel_media":1572099187,"seen":1572099187,"owner":{"__typename":"GraphUser","id":"6619361585","profile_pic_url":"https://instagram.fbeg5-1.fna.fbcdn.net/vp/e56294e9abfe45f7c2ae2de54d208557/5E50CBDA/t51.2885-19/s150x150/53740023_372495643602512_1074420510437146624_n.jpg?_nc_ht=instagram.fbeg5-1.fna.fbcdn.net","username":"ozbiljne_teme"}}}},{"node":{"id":"706629897","username":"mylifeaskitty","full_name":"Marija Zdravkovi\u0107","profile_pic_url":"https://instagram.fbeg5-1.fna.fbcdn.net/vp/ac6a53a0cb435d9900ee3984d153ae45/5E5C08E3/t51.2885-19/s150x150/66851574_2354137708132240_8606310035284295680_n.jpg?_nc_ht=instagram.fbeg5-1.fna.fbcdn.net","is_private":false,"is_verified":false,"followed_by_viewer":true,"requested_by_viewer":false,"reel":{"id":"706629897","expiring_at":1572210555,"has_pride_media":false,"latest_reel_media":0,"seen":null,"owner":{"__typename":"GraphUser","id":"706629897","profile_pic_url":"https://instagram.fbeg5-1.fna.fbcdn.net/vp/ac6a53a0cb435d9900ee3984d153ae45/5E5C08E3/t51.2885-19/s150x150/66851574_2354137708132240_8606310035284295680_n.jpg?_nc_ht=instagram.fbeg5-1.fna.fbcdn.net","username":"mylifeaskitty"}}}},{"node":{"id":"192815961","username":"gordongram","full_name":"Gordon Ramsay","profile_pic_url":"https://instagram.fbeg5-1.fna.fbcdn.net/vp/ca58f7dd68612bc05924e171092bcecf/5E579BFC/t51.2885-19/s150x150/26429265_1801356139896204_7973709430447407104_n.jpg?_nc_ht=instagram.fbeg5-1.fna.fbcdn.net","is_private":false,"is_verified":true,"followed_by_viewer":true,"requested_by_viewer":false,"reel":{"id":"192815961","expiring_at":1572210555,"has_pride_media":false,"latest_reel_media":0,"seen":null,"owner":{"__typename":"GraphUser","id":"192815961","profile_pic_url":"https://instagram.fbeg5-1.fna.fbcdn.net/vp/ca58f7dd68612bc05924e171092bcecf/5E579BFC/t51.2885-19/s150x150/26429265_1801356139896204_7973709430447407104_n.jpg?_nc_ht=instagram.fbeg5-1.fna.fbcdn.net","username":"gordongram"}}}},{"node":{"id":"19841914826","username":"vandometa_vlog","full_name":"","profile_pic_url":"https://instagram.fbeg5-1.fna.fbcdn.net/vp/2d6c970339a04d31010618e05763e7c1/5E431AE5/t51.2885-19/s150x150/67943135_2416133855379280_5169818650630160384_n.jpg?_nc_ht=instagram.fbeg5-1.fna.fbcdn.net","is_private":false,"is_verified":false,"followed_by_viewer":true,"requested_by_viewer":false,"reel":{"id":"19841914826","expiring_at":1572210555,"has_pride_media":false,"latest_reel_media":0,"seen":null,"owner":{"__typename":"GraphUser","id":"19841914826","profile_pic_url":"https://instagram.fbeg5-1.fna.fbcdn.net/vp/2d6c970339a04d31010618e05763e7c1/5E431AE5/t51.2885-19/s150x150/67943135_2416133855379280_5169818650630160384_n.jpg?_nc_ht=instagram.fbeg5-1.fna.fbcdn.net","username":"vandometa_vlog"}}}},{"node":{"id":"203227483","username":"tommycashworld","full_name":"TOMM\u00a5 \u20acA$H","profile_pic_url":"https://instagram.fbeg5-1.fna.fbcdn.net/vp/130807ffdb11359677afba2220b62875/5E617C39/t51.2885-19/s150x150/73307916_1416703575159030_5557531713581613056_n.jpg?_nc_ht=instagram.fbeg5-1.fna.fbcdn.net","is_private":false,"is_verified":true,"followed_by_viewer":true,"requested_by_viewer":false,"reel":{"id":"203227483","expiring_at":1572210555,"has_pride_media":false,"latest_reel_media":0,"seen":null,"owner":{"__typename":"GraphUser","id":"203227483","profile_pic_url":"https://instagram.fbeg5-1.fna.fbcdn.net/vp/130807ffdb11359677afba2220b62875/5E617C39/t51.2885-19/s150x150/73307916_1416703575159030_5557531713581613056_n.jpg?_nc_ht=instagram.fbeg5-1.fna.fbcdn.net","username":"tommycashworld"}}}},{"node":{"id":"4060156840","username":"fourtwenty","full_name":"Four Twenty","profile_pic_url":"https://instagram.fbeg5-1.fna.fbcdn.net/vp/2d1136bc4a84cfbf432655ebd98e4070/5E5EE4DC/t51.2885-19/s150x150/70594066_1368719939948662_8046432933394776064_n.jpg?_nc_ht=instagram.fbeg5-1.fna.fbcdn.net","is_private":true,"is_verified":false,"followed_by_viewer":true,"requested_by_viewer":false,"reel":{"id":"4060156840","expiring_at":1572210555,"has_pride_media":false,"latest_reel_media":0,"seen":null,"owner":{"__typename":"GraphUser","id":"4060156840","profile_pic_url":"https://instagram.fbeg5-1.fna.fbcdn.net/vp/2d1136bc4a84cfbf432655ebd98e4070/5E5EE4DC/t51.2885-19/s150x150/70594066_1368719939948662_8046432933394776064_n.jpg?_nc_ht=instagram.fbeg5-1.fna.fbcdn.net","username":"fourtwenty"}}}},{"node":{"id":"6945680089","username":"lazybrain.ai","full_name":"LazyBrain Initiative","profile_pic_url":"https://instagram.fbeg5-1.fna.fbcdn.net/vp/8b8324c443ffe3de2aa80641d2a9a8de/5E5BE2F3/t51.2885-19/s150x150/27879053_781778075349644_4543882190064189440_n.jpg?_nc_ht=instagram.fbeg5-1.fna.fbcdn.net","is_private":false,"is_verified":false,"followed_by_viewer":true,"requested_by_viewer":false,"reel":{"id":"6945680089","expiring_at":1572210555,"has_pride_media":false,"latest_reel_media":0,"seen":null,"owner":{"__typename":"GraphUser","id":"6945680089","profile_pic_url":"https://instagram.fbeg5-1.fna.fbcdn.net/vp/8b8324c443ffe3de2aa80641d2a9a8de/5E5BE2F3/t51.2885-19/s150x150/27879053_781778075349644_4543882190064189440_n.jpg?_nc_ht=instagram.fbeg5-1.fna.fbcdn.net","username":"lazybrain.ai"}}}},{"node":{"id":"17100242394","username":"lifewith_crohn","full_name":"Mb.Crohn","profile_pic_url":"https://instagram.fbeg5-1.fna.fbcdn.net/vp/916a9a84175036f50a6a598457759364/5E41A323/t51.2885-19/s150x150/66674988_2903343653224618_4794522445505626112_n.jpg?_nc_ht=instagram.fbeg5-1.fna.fbcdn.net","is_private":false,"is_verified":false,"followed_by_viewer":true,"requested_by_viewer":false,"reel":{"id":"17100242394","expiring_at":1572210555,"has_pride_media":false,"latest_reel_media":0,"seen":null,"owner":{"__typename":"GraphUser","id":"17100242394","profile_pic_url":"https://instagram.fbeg5-1.fna.fbcdn.net/vp/916a9a84175036f50a6a598457759364/5E41A323/t51.2885-19/s150x150/66674988_2903343653224618_4794522445505626112_n.jpg?_nc_ht=instagram.fbeg5-1.fna.fbcdn.net","username":"lifewith_crohn"}}}},{"node":{"id":"5355293","username":"andy_mann","full_name":"Andy Mann","profile_pic_url":"https://instagram.fbeg5-1.fna.fbcdn.net/vp/e12200c75630dc7e1b2b814cb649d066/5E5E764B/t51.2885-19/s150x150/68862836_2425862274407548_3512337272991121408_n.jpg?_nc_ht=instagram.fbeg5-1.fna.fbcdn.net","is_private":false,"is_verified":true,"followed_by_viewer":true,"requested_by_viewer":false,"reel":{"id":"5355293","expiring_at":1572210555,"has_pride_media":false,"latest_reel_media":0,"seen":null,"owner":{"__typename":"GraphUser","id":"5355293","profile_pic_url":"https://instagram.fbeg5-1.fna.fbcdn.net/vp/e12200c75630dc7e1b2b814cb649d066/5E5E764B/t51.2885-19/s150x150/68862836_2425862274407548_3512337272991121408_n.jpg?_nc_ht=instagram.fbeg5-1.fna.fbcdn.net","username":"andy_mann"}}}},{"node":{"id":"47457589","username":"istrahinja","full_name":"BJJ SANDMAN","profile_pic_url":"https://instagram.fbeg5-1.fna.fbcdn.net/vp/a378f9ecc6df8cd0018088b6cfc5a5f5/5E4FC0A4/t51.2885-19/s150x150/19051700_1874715819469896_2141424226534424576_a.jpg?_nc_ht=instagram.fbeg5-1.fna.fbcdn.net","is_private":true,"is_verified":false,"followed_by_viewer":true,"requested_by_viewer":false,"reel":{"id":"47457589","expiring_at":1572210555,"has_pride_media":false,"latest_reel_media":0,"seen":null,"owner":{"__typename":"GraphUser","id":"47457589","profile_pic_url":"https://instagram.fbeg5-1.fna.fbcdn.net/vp/a378f9ecc6df8cd0018088b6cfc5a5f5/5E4FC0A4/t51.2885-19/s150x150/19051700_1874715819469896_2141424226534424576_a.jpg?_nc_ht=instagram.fbeg5-1.fna.fbcdn.net","username":"istrahinja"}}}},{"node":{"id":"2158133293","username":"mpudja21","full_name":"\u041c\u0438\u0445\u0430\u0438\u043b\u043e \u041f\u0443\u0452\u0430","profile_pic_url":"https://instagram.fbeg5-1.fna.fbcdn.net/vp/881e653f5d56d596133577f67a4a7e11/5E55C1F8/t51.2885-19/s150x150/74693418_1328190550698806_2099261116705144832_n.jpg?_nc_ht=instagram.fbeg5-1.fna.fbcdn.net","is_private":false,"is_verified":false,"followed_by_viewer":true,"requested_by_viewer":false,"reel":{"id":"2158133293","expiring_at":1572210555,"has_pride_media":false,"latest_reel_media":0,"seen":1572031575,"owner":{"__typename":"GraphUser","id":"2158133293","profile_pic_url":"https://instagram.fbeg5-1.fna.fbcdn.net/vp/881e653f5d56d596133577f67a4a7e11/5E55C1F8/t51.2885-19/s150x150/74693418_1328190550698806_2099261116705144832_n.jpg?_nc_ht=instagram.fbeg5-1.fna.fbcdn.net","username":"mpudja21"}}}},{"node":{"id":"3998316794","username":"nature","full_name":"Nature","profile_pic_url":"https://instagram.fbeg5-1.fna.fbcdn.net/vp/2a4e907cbba6de380a178c95bc560376/5E49D099/t51.2885-19/s150x150/37130772_219216685405605_2651841279612157952_n.jpg?_nc_ht=instagram.fbeg5-1.fna.fbcdn.net","is_private":false,"is_verified":false,"followed_by_viewer":true,"requested_by_viewer":false,"reel":{"id":"3998316794","expiring_at":1572210555,"has_pride_media":false,"latest_reel_media":0,"seen":null,"owner":{"__typename":"GraphUser","id":"3998316794","profile_pic_url":"https://instagram.fbeg5-1.fna.fbcdn.net/vp/2a4e907cbba6de380a178c95bc560376/5E49D099/t51.2885-19/s150x150/37130772_219216685405605_2651841279612157952_n.jpg?_nc_ht=instagram.fbeg5-1.fna.fbcdn.net","username":"nature"}}}},{"node":{"id":"1808243250","username":"dobrotamilica","full_name":"\u13a0\u273a\u266d\u053b\u273a\u0442\u0394","profile_pic_url":"https://instagram.fbeg5-1.fna.fbcdn.net/vp/2b00e1cb3545393726a0bf1236e6c678/5E5DA2A1/t51.2885-19/s150x150/68908088_518976712264164_5633269725225025536_n.jpg?_nc_ht=instagram.fbeg5-1.fna.fbcdn.net","is_private":true,"is_verified":false,"followed_by_viewer":true,"requested_by_viewer":false,"reel":{"id":"1808243250","expiring_at":1572210555,"has_pride_media":false,"latest_reel_media":1572114311,"seen":1572114311,"owner":{"__typename":"GraphUser","id":"1808243250","profile_pic_url":"https://instagram.fbeg5-1.fna.fbcdn.net/vp/2b00e1cb3545393726a0bf1236e6c678/5E5DA2A1/t51.2885-19/s150x150/68908088_518976712264164_5633269725225025536_n.jpg?_nc_ht=instagram.fbeg5-1.fna.fbcdn.net","username":"dobrotamilica"}}}},{"node":{"id":"8738182557","username":"majceezmajcee","full_name":"Marija Palurovic","profile_pic_url":"https://instagram.fbeg5-1.fna.fbcdn.net/vp/ec6c203798b97791d8b0b6f1184f30d1/5E4FFACB/t51.2885-19/s150x150/57198888_414265232485760_3344820921243271168_n.jpg?_nc_ht=instagram.fbeg5-1.fna.fbcdn.net","is_private":true,"is_verified":false,"followed_by_viewer":true,"requested_by_viewer":false,"reel":{"id":"8738182557","expiring_at":1572210555,"has_pride_media":false,"latest_reel_media":0,"seen":null,"owner":{"__typename":"GraphUser","id":"8738182557","profile_pic_url":"https://instagram.fbeg5-1.fna.fbcdn.net/vp/ec6c203798b97791d8b0b6f1184f30d1/5E4FFACB/t51.2885-19/s150x150/57198888_414265232485760_3344820921243271168_n.jpg?_nc_ht=instagram.fbeg5-1.fna.fbcdn.net","username":"majceezmajcee"}}}},{"node":{"id":"1637485905","username":"niinamilanovic","full_name":"\u2664 N I N A \u2664","profile_pic_url":"https://instagram.fbeg5-1.fna.fbcdn.net/vp/ade9b86fc3985e70ab7c367b2cae4a26/5E50F5B7/t51.2885-19/s150x150/46354126_723371064697517_1754088811467374592_n.jpg?_nc_ht=instagram.fbeg5-1.fna.fbcdn.net","is_private":false,"is_verified":false,"followed_by_viewer":true,"requested_by_viewer":false,"reel":{"id":"1637485905","expiring_at":1572210555,"has_pride_media":false,"latest_reel_media":0,"seen":null,"owner":{"__typename":"GraphUser","id":"1637485905","profile_pic_url":"https://instagram.fbeg5-1.fna.fbcdn.net/vp/ade9b86fc3985e70ab7c367b2cae4a26/5E50F5B7/t51.2885-19/s150x150/46354126_723371064697517_1754088811467374592_n.jpg?_nc_ht=instagram.fbeg5-1.fna.fbcdn.net","username":"niinamilanovic"}}}}]}}},"status":"ok"}
EDIT 2:
Cookies were the problem, thats I was getting an empty JSON.
But I still dont know why
console.log(json_obj.node.username);
does not work.
It gives me this error:
Uncaught TypeError: Cannot read property 'username' of undefined
at :10:32
EDIT 3:
I've solved it with this code:
for (const node of json_obj.data.user.edge_follow.edges)
console.log(node.node.username);
in the json you posted above there is no tag username. To get to the user name you need to do json_obj.node.username
XMLHttpRequest is asynchronous, meaning that calling .open() and then .send() doesn't mean the request is complete after these calls.
Instead, you should set a function to the .onreadystatechange property like this:
var Httpreq = new XMLHttpRequest();
Httpreq.onreadystatechange = function() {
var json_obj = JSON.parse(this.responseText;
console.log(json_obj.username);
};
Httpreq.open("GET",yourUrl,false);
Httpreq.send(null);

JSON Reader issue: cannot access jsonData

I have a strange thing going on here: I am using a JSON reader within a store to fetch search results. After loading the store I receive data or error states (built together as a JSON, too). So in both ways I get a successfully response, so I have to check the JSON for myself to trap "error conditions". But I cannot access the jsonData property that shhould be a JSON object within the reader. Chrome tells me that:
I can access the applyDefaults though (it returns true in that case) but not the jsonData.
My code looks like this:
var result = searchStore.getProxy().getReader();
console.log(result.jsonData);
The output is "undefined". As you can see in the picture the jsonData object holds my JSON (with the isError property I wanted to access).
What I am doing wrong?
You need to think more async and think of the timing it takes for a request to return and when you are trying to get the jsonData. Instead of using console.log, set a breakpoint or use the debugger; statement so you can freeze the browser and walk through the code. You can then inspect variables and such to see what the object looks like.
Try to access your JSON data in a success callback, to make sure the data is gathered from the server.

How to access Json type returned from server?

Guys I have this response from server:
{"copy_am_email":"0","locations": [array here ... .....]}
which im pretty sure is a json type (I console logged it). That data above is fetched by ajax:
success : function ( data ) {
alert (data.locations[index]); //I should be able to access locations even without index
}
But my problem is locations is undefined. Or even copy_am_email. I accessed it like this:
data.locations . I even tried this data['locations'].
u have to parse it:
newJSON = JSON.parse( myJson );
i should note that you have the number zero as a string "0" it should just be 0.
Try to parse the JSON data using javascript's native method JSON.parse(data). Then try accessing locations the way you do.

Twitter Bootstrap Typeahead With Static Data

I need to use typeahead for very large data. Generation of data consumes 4-5 seconds. So I cannot make Ajax calls each time. I download and cache the data upon user request. My code is the following:
$("#build-package-list-btn").click(function(){
$.get**JSON**("/packages", function(data){
// data is an array
$("#typeahead-packages").typeahead({source:data});
console.log(data == null); // returns false
});
})
It gives no error but whenever I try to write to typeahead text box, it gives me the following error:
Uncaught TypeError: Cannot call method 'toLowerCase' of null bootstrap.js:1644
Typeahead.matcher bootstrap.js:1644
(anonymous function) bootstrap.js:1631
e.extend.grep jquery-1.7.2.min.js:2
Typeahead.lookup bootstrap.js:1630
Typeahead.keyup bootstrap.js:1738
e.extend.proxy.g jquery-1.7.2.min.js:2
f.event.dispatch jquery-1.7.2.min.js:3
f.event.add.h.handle.i jquery-1.7.2.min.js:3
My typeahead is like this (JADE)
input#typeahead-packages(type="text",data-provide="typeahead")
Also in the Chrome Console I tried:
$("#typeahead-packages").typeahead({source:["abcdef","abcddd","abcccc"]});
But typeahead does not give an error but it also does not work. I cannot find what am I doing wrong. I am using the 2.0.4 bootstrap.
EDIT: I changed it to getJSON from get it did not help. However when I construct data like this, it is working:
data = [new String((data[0])), new String((data[5]))];
Based on your update, the problem comes from the JSON.
jQuery.getJSON()
Important: As of jQuery 1.4, if the JSON file contains a syntax error, the request will usually fail silently.
(source)
You should concentrate on the source of the items. be sure that this is an array of strings. Your error suggest data is a string.
You can use the Chrome Console (or any of your choice), under the Network tab, and spy on the actual results of your AJAX request. JSONLint is an interesting tool to validate your result.
Then your next problem will be to update the source of an already initialized typeahead. You can use the following code :
var $myTypeahead = $('#myTypeahead');
var typeaheadObj = $myTypeahead.data('typeahead');
if(typeaheadObj) typeaheadObj.source = ["abc", "cde"];
Example (jsfiddle)

Accessing JSON values with a variable

I'm trying to access JSON data with jQuery and grab a specific set of values based on a variable. I've done this before using [] but for some reason I can't figure out what is going wrong this time.
My JSON file (being read in by getJSON, and named jsonmaker.php) looks like this:
{"0107001":{"label":"Canada","x":"0","y":"0.34"},"0107002":{"label":"USA","x":"-0.16","y":"0.53"}}
I then have a function which is essentially this:
function addAttrib(attrib) {
$.getJSON("jsonmaker.php", function(data) {
alert(data[attrib].label);
}
}
But it keeps returning undefined. Any idea what I'm doing wrong? I've checked to make sure the var going to attrib is 0107001, no problems there.
Also, I know my JSON file is a php file so I could filter what's returned to match the attrib value, but I'm looking to develop something that can run purely on HTML and JS, so I could just pack the JSON file for the project and take it with me. No need for a web server w/ PHP etc.
The data access itself works for me:
var data = {"0107001":{"label":"Canada","x":"0","y":"0.34"},"0107002":{"label":"USA","x":"-0.16","y":"0.53"}};
var attrib = "0107002";
alert(data[attrib].label); // USA
Make sure that attrib remains untouched between the moment you call addAttrib() and the moment when the AJAX request completes and your anonymous callback function gets called.
Update: is this your real code? You have at least one syntax error:
function addAttrib(attrib) {
$.getJSON("jsonmaker.php", function(data) {
alert(data[attrib].label);
}); // <- Please note missing ");"
}
In my experience, $.getJSON() doesn't always return an object. Depending on the MIME type that the server returns along with the JSON, you might end up with a string instead of an object. Check what data contains. If it's a string, you must manually parse it using eval() (old style) or JSON.parse() (new browsers only).
try to list all properties from data, to have sure the data is being returned:
for (var p in data){
if (data.hasOwnProperty(p){
alert(data[p]);
}
}
It's not your solution but with this you can know how your data is coming.

Categories

Resources