我无法从场地搜索中读取JSON数据。这里是我的代码:处理JSON结果
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);
}
}
}
我得到我从服务器所期望的效应初探,并萤火表明我会返回一个JSON对象,但我不知道如何从访问里面的数据这里。
的console.log(recRes.meta.code)返回错误:
“recRes.meta未定义”
我要去哪里错了? 我想访问场馆信息,但我只是使用meta.code作为一个简单的测试。 这可能很简单,但我很难过!
在此先感谢, 罗斯。
感谢回复的家伙。使用JSON.parse(recRes)给出错误:JSON.parse:意外字符。你认为它是因为JSON数据从JSONP开始? – user1229498 2012-02-23 22:51:04
JSONP是另一个故事,如[这里]声明(http://stackoverflow.com/questions/3543513/how-to-parse-jsonp-data-returned-from-remote-server) – raina77ow 2012-02-23 23:00:29
我已经要求它为JSON现在,它是返回JSON(... 但我仍然得到错误: JSON.parse:意外的字符 VAR recResD = JSON.parse(recRes); – user1229498 2012-02-23 23:06:18