3 回答
TA贡献1836条经验 获得超3个赞
您可以使用array_walk以获得所需的结果
$json1 = '{
"Zipcode":"22581",
"City":"",
"Primary State":"Maryland",
"Common Field":"49969",
"County":"Something"
}';
$json2 = '{
"Common Field":"49969",
"Option 1":"Y",
"Option 2":"",
"Option 3":""
}';
$json1Array = json_decode($json1, true);
$json2Array = json_decode($json2, true);
array_walk($json1Array, function($value, $key) use (&$json1Array, $json2Array){
$json1Array['Common Field'] = $json2Array;
});
$result = json_encode($json1Array);
TA贡献1785条经验 获得超8个赞
试试这个:
$json1 = (array)json_decode(file_get_contents('json1.json'));
$json2 = (array)json_decode(file_get_contents('json2.json'));
$json1['Common Field'] = $json2;
echo json_encode($json1, JSON_PRETTY_PRINT);
输出:
{
"Zipcode": "22581",
"City": "",
"Primary State": "Maryland",
"Common Field": {
"Common Field": "49969",
"Option 1": "Y",
"Option 2": "",
"Option 3": ""
},
"County": "Something"
}
- 3 回答
- 0 关注
- 209 浏览
添加回答
举报