1. Application of json in Ajax
For processing of large batches of data:
1) xml
2) json
1. About json
An object is an unordered collection of attributes
In js, you can use {} to simulate an unordered collection of attributes
1. About json in php
Currently, most ajax programs use json objects as data transfer methods, so many languages have built-in support for json objects. In php, there are two functions for encoding and decoding json
l string json_encode ( mixed $value )
Generate string in json format
l mixed json_decode ( string $json [, bool])
Parse json
The second parameter indicates whether to parse into an array or an object. The default is false, which means parsing into an object
1) json_encode
If you want to get data in json format, you must first get an array or object
2) json_decode
3) json_decode
Json currently only supports utf-8 format
3. Ajax uses json
Example 1: Using json to return four arithmetic operations of two numbers
Server code:
Example 2: Return multiple pieces of data from the server
Ajax program:
Php program: