Many websites now use asynchronous loading technology, and most of the loaded data formats are json (such as {"order":"205","205":"u81eau9009u80a1"}), which are listed below. Below are several ways to read data in PHP and convert it into json output.
The first, simplest and most commonly used method is to spell strings. I won’t introduce it in detail here
The second method is to use the json_encode function
Execute the following code
[php]
var_dump(json_decode('{"order":"205","205":"u81ea"}'));
var_dump(json_decode('{"order":"205","205":"u81ea"}'));
The final result is:
object(stdClass)#1 (2) { ["order"]=> string(3) "205" ["205"]=> string(3) "from" }
Therefore, you need to define an stdClass object before conversion, assign it a value and execute the json_encode function to get the required results.
Later I discovered that defining an array is also possible, as long as the final array format is: array(order=>205,"205"=>"u81ea"). In this case, new elements are added to the array. If so, you cannot use array_push, but assign the value through index $arr["order"]="205";
The advantages and disadvantages of both
The execution speed of the first method is relatively faster than the second one (I have done a demo test). The disadvantage is that when spelling strings, there are a lot of quotation marks, and it is easy to make mistakes if you are not careful
The second one is more in line with the habits of object-oriented programming and will encode Chinese unicode. The disadvantage is that there is more process of packaging data and parsing the data, so the speed will be relatively slower, but it is completely acceptable