1. I need to accept JSON array data in the following format to render
[{date: "2018-06-09", Data: "1"}, {date: "2018-06-23", Data: "Aadsf34"}, {date: "2018-07-02", Data: "3"},]
2, server PHP How to output can be JS parsed into the above data?
PHP Output: (String)
foreach ($arras$value) { $json . = Json_encode ($value). ', 'echosubstr($json, 0,strlen($json)-1). ‘]‘;
Json_encode () is JSON-encoded for each value of $arr, and then we want to output a JSON array, so we add a comma after each compiled value and finally add ' [] ' to all the values, which is the format of the JSON array, Note that because we add a comma after each value is JSON encoded, this results in a comma when all the last values merge the array, all of which we have to use the substr () function to remove the last comma!
3. then we look at the JS file
After we have accepted the JSON array to the PHP file transfer with arr:(foreground JSON parses the string into a JSON array)
var json = Json.parse (arr);
JSON is the object we started to download in that file, and we use its Parse method to convert the JSON array into a JS array! This is the variable JSON is received by a JS array so directly can not print out, you can traverse this JSON array or json[0] to output!
"Php+js" JSON usage of the PHP array to JS array, JS How to receive the PHP array