The knowledge of this article: 1, JSON data format introduction, 2, the data encoded into JSON format, 3, the JSON data decoding, and operation, the need for small partners can refer to.
JSON, the full name is the JavaScript Object notation. It is a lightweight data interchange format based on the JavaScript programming language ECMA-262 3rd Edition-december 1999 standard, mainly for exchanging data with the server. Like XML, it has a lot of advantages over cross-platform data transfer, independent of language.
To create a new file json.php, do the Encode action first:
?
| 1 2 3 4 |
Encode//Generate JSON Format data $arr = Array (1,2,3,4,5,6,7,8,9, ' Hello ', ' PHP '); echo Json_encode ($arr);//json_encode: Converts an object into JSON-formatted data |
The result is [1,2,3,4,5,6,7,8,9, "Hello", "PHP"]
Then do the decode operation:
?
| 1 2 3 4 |
Decode decoding $jsonStr = ' {' h ': ' Hello ', ' W ': ' World ', ' 0 ': [3,2,1]} '; $obj = Json_decode ($JSONSTR); echo $obj->h;//use member access to get results |
After you know the simple way to use, you can try to catch API data, such as weather ...
The above mentioned is the entire content of this article, I hope you can enjoy.