【发布时间】:2019-01-15 11:06:32
【问题描述】:
我有一个从服务器获得的 JSON 响应,如下所示
{
"questionList": [{
"qno": "1",
"state_name": "State1",
"category_name": "Category1",
"question_type": "type1",
"question": "This is question 11",
"options": ["No", "yes "]
},
{
"qno": "2",
"state_name": "State1",
"category_name": "Category1",
"question_type": "type1",
"question": "This is question12",
"options": ["No", "yes "]
},
{
"qno": "3",
"state_name": "State1",
"category_name": "Category2",
"question_type": "type2",
"question": "This is question 21",
"options": ["No ", "yes "]
},
{
"qno": "4",
"state_name": "State1",
"category_name": "Category3",
"question_type": "type1",
"question": "This is question 31",
"options": ["No ", "yes "]
},
{
"qno": "5",
"state_name": "State1",
"category_name": "Category3",
"question_type": "type1",
"question": "This is question 32",
"options": ["No ", "yes "]
}
]
}
现在我想根据类别对其进行重组,以便具有多个相同类别的问题将属于一个类别,并且我自己的变量也很少。下面是它应该是什么样子的示例输出。
[
{
"state": "State1",
"category": "Category1",
"questions": [
{
"questionID": "1",
"question": "This is question 11",
"options": ["No ", "yes "],
"status": 0,
"files": [],
"questionType": "type1"
},
{
"questionID": "2",
"question": "This is question12",
"options": ["No ", "yes "],
"status": 0,
"files": [],
"questionType": "type1"
}
]
},
{
"state": "State1",
"category": "Category2",
"questions": [
{
"questionID": "3",
"question": "This is question 21",
"options": ["No ", "yes "],
"status": 0,
"files": [],
"questionType": "type2"
}
]
},
{
"state": "State1",
"category": "Category3",
"questions": [
{
"questionID": "4",
"question": "This is question 31",
"options": ["No ", "yes "],
"status": 0,
"files": [],
"questionType": "type1"
},
{
"questionID": "5",
"question": "This is question 32",
"options": ["No ", "yes "],
"status": 0,
"files": [],
"questionType": "type1"
}
]
}
]
我并不是 JSON 操作方面的专家。谁能告诉我这应该是解决这个问题的最佳方法吗?
【问题讨论】:
-
一个类别可以有多个状态吗?
-
不,特定类别只允许一个状态。
标签: android ios json reactjs react-native