我想用angularjs来实现问卷,所以我有下面的响应数组,我需要将这个对象数组转换为json格式,就像下面的输出那样,我怎样才能将对象数组转换为json格式?AngularJS将json格式转换成另一种json格式
var response=[{"questiongroup":1,"question":1,"response":"response1"},
{"questiongroup":1,"question":2,"response":"response2"},
{"questiongroup":1,"question":3,"response":"response3"},
{"questiongroup":1,"question":4,"response":"response4"},
{"questiongroup":1,"question":5,"response":"response5"},
{"questiongroup":2,"question":6,"response":"response6"},
{"questiongroup":2,"question":7,"response":"response7"},
{"questiongroup":2,"question":8,"response":"response8"},
{"questiongroup":2,"question":9,"response":"response9"},
{"questiongroup":2,"question":10,"response":"response10"}];
所需的输出
{"questiongroups": [
{
"questiongroup": 1,
"question": [
{
"question": 1,
"response":"response1"
},
{
"question": 2,
"response":"response2"
},
{
"question": 3,
"response":"response3"
},
{
"question": 4,
"response":"response4"
},
{
"question": 5,
"response":"response5"
}]
},
{
"questiongroup": 2,
"question": [
{
"question": 6,
"response":"response6"
},
{
"question": 7,
"response":"response7"
},
{
"question": 8,
"response":"response8"
},
{
"question": 9,
"response":"response9"
},
{
"question": 10,
"response":"response10"
}]
}
]
}
对不起,我是在这个标记为重复的太仓促 - 看来,你不问如何到这个对象到JSON转换,你问如何重新安排数据转换成不同的结构。 –
是的,它不同我需要更改格式。 –
你尝试过什么吗?像这样的数据突变非常普遍。 –