我的Json在PHP這樣的:如何在PHP中添加JSON屬性?
$json = '{"total":"100", "page":"1", "records":"100", "rows": [
{"no":"1","part_number":"2","part_name":"3","price":"4","note":"8"}]}';
,我想補充
"test1":"5","test2":"7"
成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"}]}';
請幫助我。如何在PHP中添加JSON屬性?
你可以使用'json_decode'解析JSON字符串數組,添加新的屬性到數組中,並使用'json_encode'重建JSON字符串。 – Vulcan
[將新數據添加到PHP JSON字符串](http://stackoverflow.com/questions/1745052/add-new-data-into-php-json-string) –
中的示例可能是http:// stackoverflow中的示例。 com/questions/1745052/add-new-data-into-php-json-string使用數組定義。 Rio希望添加屬性(屬性) – user20232359723568423357842364