我从远程服务器返回以下 JSON:
{
"success": true,
"questions": [{
"id": 23,
"text": "Is Sky Blue?",
"response_type": "Multiple Choice",
"created_at": "2014-12-05T06:37:20.947Z",
"updated_at": "2015-03-04T00:00:56.915Z",
"campaign_id": 38,
"no_repeats": true,
"max_repeat": 0,
"yes_no": false,
"type": "axy",
"priority": 0
}, {
"id": 24,
"text": "What is your current employment status?",
"response_type": "Multiple Choice",
"created_at": "2014-12-05T06:38:56.076Z",
"updated_at": "2015-03-04T00:00:56.903Z",
"campaign_id": 38,
"no_repeats": true,
"max_repeat": 0,
"yes_no": false,
"type": "axy",
"priority": 0
}]
}
我使用此代码从远程 URL 获取数据:
$.get( url, function( data ){
alert(data.success); // Works
alert(data. questions); // Returns Blank
});
data.questions
返回空。我尝试eval
,但它只返回[object]
我做错了什么?
最佳答案
questions
是一个数组。尝试一下
alert(data.questions[0].id)
您应该得到 23。如果这样做,您将获得访问其余数据所需的洞察力。
关于javascript - 无法解析来自远程服务器的 JavaScript 中的 JSON,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28920478/