【发布时间】:2016-09-12 16:32:35
【问题描述】:
我有以下...
$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?
【问题讨论】:
-
你真的想要一个包含 1 个对象的数组吗?
-
这会是一件需要经常发生的事情,真的很快吗?你可以
json_decode,然后随意拼接,然后用json_encode()重新编码