我从远程服务器返回以下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]
我做错了什么?
答案 0 :(得分:3)
questions
是一个数组。试试
alert(data.questions[0].id)
你应该得到23.如果你这样做,那将为你提供访问其余数据所需的洞察力。