我有一个问题,我有一些要通过API作为JSON返回的数据的多维数组,我希望将数据作为JSON数组,该数组在PHP中的结构正确,但是当我通过API返回时, JSON成为对象的JSON对象,我想要的数据与生成数组时在PHP中保存的结构相同。我尝试将对象转换为数组,数组在PHP中是完美的,但在JSON中它成为对象的对象。我如何返回JSON数据作为数组。
{
"standards":{
"standard_1":{
"subjects":{
"English":{
"topics":[
]
},
"Physics":{
"topics":{
"topic":[
{
"id":"2",
"standard_id":"1",
"subject_id":"3",
"topic":"topic",
"title":"dgfdgfdg",
"option_1":"dfgdfggdgfdg",
"option_2":"dfgfd",
"option_3":"gdfgfdg",
"option_4":"dfgdfgdg",
"correct_answer":"option_2"
}
],
"test topic":[
{
"id":"6",
"standard_id":"1",
"subject_id":"3",
"topic":"test topic",
"title":"title",
"option_1":"1",
"option_2":"2",
"option_3":"3",
"option_4":"4",
"correct_answer":"option_2"
}
]
}
},
"sports":{
"topics":[
]
},
"Maths":{
"topics":{
"topic":[
{
"id":"1",
"standard_id":"1",
"subject_id":"21",
"topic":"topic",
"title":"This is a updated test question",
"option_1":"1",
"option_2":"2",
"option_3":"3",
"option_4":"4",
"correct_answer":"option_2"
}
]
}
},
"test subject":{
"topics":[
]
}
}
},
"standard_2":{
"subjects":{
"Math":{
"topics":[
]
},
"Chemistry":{
"topics":{
"topic":[
{
"id":"4",
"standard_id":"2",
"subject_id":"4",
"topic":"topic",
"title":"sfsfsfs",
"option_1":"fdsfs",
"option_2":"fsfs",
"option_3":"fsdfsdf",
"option_4":"sdfdsfds",
"correct_answer":"option_1"
}
]
}
},
"test sub":{
"topics":{
"fghgfh":[
{
"id":"3",
"standard_id":"2",
"subject_id":"19",
"topic":"fghgfh",
"title":"Title",
"option_1":"fhfhf",
"option_2":"hfhf",
"option_3":"hgfhf",
"option_4":"fhfghfhfh",
"correct_answer":"option_4"
}
]
}
}
}
},
"standard_3":{
"subjects":{
"Sports":{
"topics":[
]
}
}
},
"standard_4":{
"subjects":{
"new subject":{
"topics":[
]
},
"Computer":{
"topics":{
"Basics":[
{
"id":"7",
"standard_id":"4",
"subject_id":"24",
"topic":"Basics",
"title":"What is a computer",
"option_1":"Machine",
"option_2":"Aeroplane",
"option_3":"Device",
"option_4":"Robot",
"correct_answer":"option_1"
}
]
}
}
}
},
"standard_5":{
"subjects":{
"Math":{
"topics":[
]
},
"":{
"topics":[
]
},
"History":{
"topics":[
]
}
}
},
"standard_6":{
"subjects":[
]
},
"standard_7":{
"subjects":{
"Sports":{
"topics":[
]
},
"Civics":{
"topics":[
]
}
}
},
"standard_8":{
"subjects":[
]
},
"standard_9":{
"subjects":[
]
},
"standard_10":{
"subjects":{
"History":{
"topics":[
]
},
"Math":{
"topics":[
]
}
}
},
"standard_11":{
"subjects":[
]
},
"standard_12":{
"subjects":[
]
}
}
}
[standard_1] => Array
(
[subjects] => Array
(
[English] => Array
(
[topics] => Array
(
)
)
[Physics] => Array
(
[topics] => Array
(
[topic] => Array
(
[0] => stdClass Object
(
[id] => 2
[standard_id] => 1
[subject_id] => 3
[topic] => topic
[title] => dgfdgfdg
[option_1] => dfgdfggdgfdg
[option_2] => dfgfd
[option_3] => gdfgfdg
[option_4] => dfgdfgdg
[correct_answer] => option_2
)
)
[test topic] => Array
(
[0] => stdClass Object
(
[id] => 6
[standard_id] => 1
[subject_id] => 3
[topic] => test topic
[title] => title
[option_1] => 1
[option_2] => 2
[option_3] => 3
[option_4] => 4
[correct_answer] => option_2
)
)
)
)
[sports] => Array
(
[topics] => Array
(
)
)
[Maths] => Array
(
[topics] => Array
(
[topic] => Array
(
[0] => stdClass Object
(
[id] => 1
[standard_id] => 1
[subject_id] => 21
[topic] => topic
[title] => This is a updated test question
[option_1] => 1
[option_2] => 2
[option_3] => 3
[option_4] => 4
[correct_answer] => option_2
)
)
)
)
[test subject] => Array
(
[topics] => Array
(
)
)
)
)
有什么主意吗?