我有两个 json
第一个是
[{"COLUMN_NAME":"ORDER_NO","COLUMN_TITLE":"Order Number"}
,{"COLUMN_NAME":"CUSTOMER_NO","COLUMN_TITLE":"Customer Number"}]
第二个是
[{"COLUMN_NAME":"ORDER_NO","DEFAULT_VALUE":"1521"},
{"COLUMN_NAME":"CUSTOMER_NO","DEFAULT_VALUEE":"C1435"}]
我想合并它们并有一个像
I want to merge them and have a json like
[{"COLUMN_NAME":"ORDER_NO","COLUMN_TITLE":"Order Number","DEFAULT_VALUE":"1521"}
,{"COLUMN_NAME":"CUSTOMER_NO","COLUMN_TITLE":"Customer Number","DEFAULT_VALUEE":"C1435"}]
有没有办法合并它们?如果需要更改 JSON 中的结构,对我来说也可以
is there a way to merge them? It is also OK for me if a stucture change in JSON is required
谢谢.
类似 json_encode(array_merge(json_decode($a, true),json_decode($b, true))) 之类的东西应该可以工作.
Something like json_encode(array_merge(json_decode($a, true),json_decode($b, true))) should work.
array_merge PHP 官方文档
array_merge in official PHP documentation
json_decode 在 PHP 官方文档中
json_decode in official PHP documentation
尝试将 true 作为第二个参数添加到 json_decode.这会将对象转换为关联数组.
try adding true as second parameter to json_decode. That'll convert objects to associative arrays.
EDIT 2:尝试 array-merge-recursive 并在下面查看我的评论.抱歉现在必须退出:(这看起来是一个完整正确的解决方案:https://stackoverflow.com/a/20286594/1466341
EDIT 2: try array-merge-recursive and see my comment below. Sorry have to log out now :(
This looks like a full correct solution: https://stackoverflow.com/a/20286594/1466341
这篇关于在 PHP 中合并两个 json的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!
PHP、MySQL PDOException 的死锁异常代码?Deadlock exception code for PHP, MySQL PDOException?(PHP、MySQL PDOException 的死锁异常代码?)
PHP PDO MySQL 可滚动游标不起作用PHP PDO MySQL scrollable cursor doesn#39;t work(PHP PDO MySQL 可滚动游标不起作用)
PHP PDO ODBC 连接PHP PDO ODBC connection(PHP PDO ODBC 连接)
使用 PDO::FETCH_CLASS 和魔术方法Using PDO::FETCH_CLASS with Magic Methods(使用 PDO::FETCH_CLASS 和魔术方法)
php pdo 只从 mysql 获取一个值;等于变量的值php pdo get only one value from mysql; value that equals to variable(php pdo 只从 mysql 获取一个值;等于变量的值)
MSSQL PDO 找不到驱动程序MSSQL PDO could not find driver(MSSQL PDO 找不到驱动程序)