I have the following...
$json1
:
[{
"id": 1,
"table_prefix": "movie",
"display_name": "Movies"
}]
$json2
:
[{
"field_name": "Title",
"column_name": "title",
"sort_order": 0,
"sort_section": 0,
"required": 1,
"relationship": "field",
"table_type": "",
"view_type": "text",
"description": "",
"multi_value": 0,
"char_count": 255
}, {
"field_name": "Synopsis",
"column_name": "synopsis",
"sort_order": 1,
"sort_section": 0,
"required": 0,
"relationship": "field",
"table_type": "",
"view_type": "longtext",
"description": "",
"multi_value": 0,
"char_count": 10000
}]
我希望
$finalJSON
的格式如下所示:
[{
"id": 1,
"table_prefix": "movie",
"display_name": "Movies",
"fields": [{
"field_name": "Title",
"column_name": "title",
"sort_order": 0,
"sort_section": 0,
"required": 1,
"relationship": "field",
"table_type": "",
"view_type": "text",
"description": "",
"multi_value": 0,
"char_count": 255
}, {
"field_name": "Synopsis",
"column_name": "synopsis",
"sort_order": 1,
"sort_section": 0,
"required": 0,
"relationship": "field",
"table_type": "",
"view_type": "longtext",
"description": "",
"multi_value": 0,
"char_count": 10000
}]
}]
有没有一个简单的PHP JSON函数,可以让我像这样将JSON数组附加到现有的JSON中?
json_decode
进行解码,然后按照您想要的方式拼接,最后使用json_encode()
进行重新编码。 - Blake