用JSON处理结果 [英] Dealing with JSON result
问题描述
我无法从场地搜索读取JSON数据。这里是我的code:
xmlhttpRC =新XMLHtt prequest();
URL = \"https://api.foursquare.com/v2/venues/explore?ll=\"+pointStrr+\"&oauth_token=V5PI2GJ0KDOVH2GAHNHJ5DVLMRKNF440FR1N1HPG0XHX2OBQ&v=2015643&
回调= JSONP;
xmlhttpRC.open(GET,网址,真实);
xmlhttpRC.onreadystatechange = recCb;
xmlhttpRC.send(NULL);
//返回recommendedArr;
}功能recCb(数据){
//console.log(data);
如果(xmlhttpRC.readyState == 4){
如果(xmlhttpRC.status == 200){
VAR recRes = xmlhttpRC.response; 的console.log(recRes); //console.log(recRes);
的console.log(recRes.meta code);
}
}
}
我得到我从服务器期望效应初探,和萤火虫让我发现,返回一个JSON对象,但我不知道如何从这里访问里面的数据。
的console.log(recRes.meta code)将返回错误:
recRes.meta未定义
我在哪里去了?
我要访问的地点信息,但我只是用元。code作为一个简单的测试。
这可能是真的简单,但我很为难!
在此先感谢,
罗斯。
VAR德codedResp = JSON.parse(recRes);
如果(德codedResp.meta。code === ...)
JSON对象仅仅是一个重新的$ JS对象的对$ psentation,看见了;应该首先分析
I'm having trouble reading the JSON data from a venues search. Here is my code:
xmlhttpRC = new XMLHttpRequest();
url = "https://api.foursquare.com/v2/venues/explore?ll="+pointStrr+"&oauth_token=V5PI2GJ0KDOVH2GAHNHJ5DVLMRKNF440FR1N1HPG0XHX2OBQ&v=2015643&
callback=JSONP";
xmlhttpRC.open("GET", url, true);
xmlhttpRC.onreadystatechange = recCb;
xmlhttpRC.send(null);
//return recommendedArr;
}
function recCb(data){
//console.log(data);
if(xmlhttpRC.readyState == 4){
if(xmlhttpRC.status == 200){
var recRes = xmlhttpRC.response;
console.log(recRes);
//console.log(recRes);
console.log(recRes.meta.code);
}
}
}
I get the reponse I expect from the server, and firebug shows me that a JSON object is returned, but I am not sure how to access the data inside from here.
console.log(recRes.meta.code) returns the error:
"recRes.meta is undefined"
Where am I going wrong? I want to access the venues information but I am just using meta.code as a simple test. This is probably really simple but I'm stumped!
Thanks in advance, Ross.
var decodedResp = JSON.parse(recRes);
if (decodedResp.meta.code === ...)
JSON-object is just a representation of an JS-object, see; it should be parsed first.
这篇关于用JSON处理结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!