嗨,我正在使用parsejson解析此JSON字符串:
json = [
{
"Answers": [
{
"Responses": [
],
"AnswerID": 1,
"AnswerText": "Green"
},
{
"Responses": [
{
"ResponseID": 1,
"RespondingUser": null,
"ResponseDate": "/Date(1351694241577)/"
},
{
"ResponseID": 2,
"RespondingUser": null,
"ResponseDate": "/Date(1351694245093)/"
}
],
"AnswerID": 2,
"AnswerText": "Blue"
}
],
"QuestionID": 1,
"QuestionText": "Favourite colour?",
"ClosingDate": "/Date(1351953058527)/",
"AskingUser": null
}
]
var result = jQuery.parseJSON(json);
但是,现在如何从"结果"中获得响应/响应ID?任何帮助将不胜感激!
[] = array
{} =对象
您有一个数组,丢失了包装方括号。
alert(json.answers [0] .answertext)=" green"
您应该能够使用for-in-in循环:
for (i in result[0].Answers)
{
// do something with result[0].Answers[i].Responses
}
这是您要寻找的吗?
for (var a in result[0].Answers) {
result[0].Answers[a].AnswerID // Do something with it.
}