这是我需要解析的 JSON:
{"opcode":"groupdetails",
"status":"success",
"data":[{"Group ID":5,"Group Name":"data structure","Group Subject":"computer science","Role Type":"Teacher"},{"Group ID":4,"Group Name":"information technology","Group Subject":"computer science","Role Type":"Student"},{"Group ID":6,"Group Name":"data mining","Group Subject":"computer science","Role Type":"Parent"},{"Group ID":7,"Group Name":"dccn","Group Subject":"computer science","Role Type":"Teacher"}]}
我已经尝试并实现了这里提供的解决方案,这是在解决方案中定义的 JS 的实现,它只解析 JSON 数组
for (var i = 0; i < data.data.length; i++)
{
var object = data.data[i];
for (property in object)
{
var value = object[property];
alert(property + "=" + value);
}
}
外部 JSON数据是从服务器返回的,是的,我尝试使用以下代码进行解析,但没有结果:
for (var i = 0; i < data.length; i++)
{
var object = data[i];
for (property in object)
{
var value = object[property];
alert(property + "=" + value);
}
}
如何使用单一方法解析整个 JSON,而不是单独解析 JSON 数组?