This article mainly introduces the details of json communication interfaces encapsulated by php and related information of instances. For more information, see the following article. it mainly introduces the details of json communication interfaces encapsulated by php and related information of instances, for more information, see
JSON data creation in php:
1, 'name' => 'David '); echo json_encode ($ arr); // is the key function for creating JSON?>
Implementation Result
{"id":1,"name":"david"}
Note: json_encode ($ value); this function can only receive UTF-8 encoded data. If data in other formats is transmitted to this function, null is returned;
Data method for encapsulating communication interfaces
1. standard communication data format:
0111 code status code (200,400). For example, if the logon succeeds at 200, the logon fails at 400.
Message (incorrect email format, 200 indicates successful logon)
Data returned data
Instance:
Demo. php
$ Code, 'message' => $ message, 'data' => $ data); echo json_encode ($ result); exit ;}}?>
The main file test. PHP calls the method of the above class to create json data
1, 'name' => 'David '); // call the json method of the Resonpse class Response: json (200, 'data returned successfully', $ arr);?>
Result of running test. php:
{"code":200,"message":"\u6570\u636e\u8fd4\u56de\u6210\u529f","data":{"id":1,"name":"david"}}
The above is the details of the json communication interface encapsulated by php and the content of the instance. For more information, please follow the PHP Chinese network (www.php1.cn )!