在PHP中创建一个用于字符串JSON的数组

时间:2017-09-27 06:22:09

标签: php json

Array
(
    [0] => {"vpg_id":"2","profile_id":"WEBCEO_1","project_id":"6b9d7206"}
    [1] => {"vpg_id":"2","profile_id":"WEBCEO_6","project_id":"896fb06f"}
    [2] => {"vpg_id":"2","profile_id":"WEBCEO_8","project_id":"90f33ff3"}
    [3] => {"vpg_id":"2","profile_id":"WEBCEO_9","project_id":"ca43eaff"}
    [4] => {"vpg_id":"2","profile_id":"WEBCEO_13","project_id":"9c2eeee1"}
    [5] => {"vpg_id":"2","profile_id":"WEBCEO_14","project_id":"57cf900e"} 
)

如何将其变为如下所示的字符串

{"vpg_id":"2","profile_id":"WEBCEO_1","project_id":"6b9d7206"}
{"vpg_id":"2","profile_id":"WEBCEO_6","project_id":"896fb06f"}
{"vpg_id":"2","profile_id":"WEBCEO_8","project_id":"90f33ff3"}
{"vpg_id":"2","profile_id":"WEBCEO_9","project_id":"ca43eaff"}
{"vpg_id":"2","profile_id":"WEBCEO_14","project_id":"57cf900e"} 

使用JSON 和PHP

2 个答案:

答案 0 :(得分:0)

使用php的函数json_encode:

json_encode($array)

或用新行破坏它:

implode("\n", $array);

答案 1 :(得分:-1)

检查 - > json_encode 使用

let stateCopy = Object.assign({}, this.state); // get the current state copy
stateCopy.photos = stateCopy.photos.slice(); // get photos object
stateCopy.photos[key] = Object.assign({}, stateCopy.photos[key]); 
stateCopy.photos[key].description = 'new decription'; // update description of specific key
this.setState(stateCopy); // set state