The PHPJSON application starts with PHP5.2. JSON support has been added since this version. There are two main functions: json_encode and json_decode.
Php json applications start with PHP5.2. JSON support has been added since this version. There are two main functions: json_encode and json_decode.
JSON is a data storage format, just like PHP serialized strings. It is a data description. For example, if we store an array after serialization, we can easily apply it after deserialization. The same is true for JSON. PHP5.2 has built-in support for JSON. Of course, if it is earlier than this version, there are many PHP versions available on the market, and it will be OK if you use it next time. Now we mainly talk about the built-in JSON supported by PHP. Very simple: two functions: json_encode and json_decode (similar to serialization ). One encoding and one decoding.
Eg:
$ Category1 = json_encode (array ("id" => "1000214", "category" => "domestic news "));
$ Category2 = json_encode (array ("id" => "1000215", "category" => "International News "));
$ Category5 = json_encode (array ("id" => "1000216", "category" => "Entertainment News "));
Echo $ category1 .'
';
Echo $ category2 .'
';
Echo $ category5 .'
';
Output:
{"Id": "1000214", "category": "/u56fd/u5185/u65b0/u95fb "}
{"Id": "1000215", "category": "/u56fd/u9645/u65b0/u95fb "}
{"Id": "1000216", "category": "/u5a31/u4e50/u65b0/u95fb "}
Eg:
Var_dump (json_decode ($ category1 )).'
';
Output:
Object (stdClass) [33] public 'id' => string '000000' (length = 7) public 'Category '=> string 'Entertainment News' (length = 12)