PHP中将两个json合并成一个json
两个json现需要合并成一个PHP中合并合并前:{"store_id":"1","store_name":"官方店铺"}{"dataList":[{"goods_id":...
两个json现需要合并成一个 PHP中合并
合并前:
{"store_id":"1","store_name":"官方店铺"}
{"dataList":[{"goods_id":"38","goods_commonid":"100008"}
{"goods_id":"39","goods_commonid":"100008"}",{"goods_id":"40","goods_commonid":"100008"}]}
合并后(样式不一定正确、但合并后要求是类似效果):
{"store_id":"1","store_name":"官方店铺","shangpuSP":"{"dataList":[{"goods_id":"38","goods_commonid":"100008"},{"goods_id":"39","goods_commonid":"100008"}",{"goods_id":"40","goods_commonid":"100008"}]}"} 展开
合并前:
{"store_id":"1","store_name":"官方店铺"}
{"dataList":[{"goods_id":"38","goods_commonid":"100008"}
{"goods_id":"39","goods_commonid":"100008"}",{"goods_id":"40","goods_commonid":"100008"}]}
合并后(样式不一定正确、但合并后要求是类似效果):
{"store_id":"1","store_name":"官方店铺","shangpuSP":"{"dataList":[{"goods_id":"38","goods_commonid":"100008"},{"goods_id":"39","goods_commonid":"100008"}",{"goods_id":"40","goods_commonid":"100008"}]}"} 展开
1个回答
2014-09-11
展开全部
假设你上面两个json分别赋值给变量 $json1 和 $json2
$newJson = json_encode(
array_merge(
json_decode($json1, true),
array('shangpuSP' => json_decode($json2, true) )
)
);
$newJson = json_encode(
array_merge(
json_decode($json1, true),
array('shangpuSP' => json_decode($json2, true) )
)
);
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询