我在PHP中使用Json是这样的:
$json = '{"total":"100", "page":"1", "records":"100", "rows": [
{"no":"1","part_number":"2","part_name":"3","price":"4","note":"8"}]}';
Run Code Online (Sandbox Code Playgroud)
我想补充一下
"test1":"5","test2":"7"
Run Code Online (Sandbox Code Playgroud)
进入JSON上面.
所以它会是这样的:
$json = '{"total":"100", "page":"1", "records":"100", "rows": [
{"no":"1","part_number":"2","part_name":"3","price":"4","test1":"5","test2":"7","note":"8"}]}';
Run Code Online (Sandbox Code Playgroud)
请帮我.如何在PHP中添加JSON中的属性?
$json = '{"total":"100", "page":"1", "records":"100", "rows": [
{"no":"1","part_number":"2","part_name":"3","price":"4","note":"8"}]}';
// decode json
$json = json_decode($json);
// add data
$json->rows[0]->test1 = "5";
$json->rows[0]->test2 = "7";
// echo it for testing puproses
print_r($json);
// re-encode
$json = json_encode($json);
echo $json;
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
5568 次 |
| 最近记录: |