For json questions, could I ask php to use json_encode to implement the output in the following format? If yes, can I send an example? Thank you very much! 1 result returned: {result: [{userid: 001, username: Li Ming}]} 2 results returned: {result: [{userid: 001, username: Zhang Fei }, {userid: 002, username: json
Can php use json_encode to implement output in the following format? If yes, can I send an example? Thank you very much!
One result is returned: {"result": [{"userid": 001, "username": "Li Ming"}]}
Two results are returned: {"result": [{"userid": 001, "username": "Zhang Fei" },{ "userid": 002, "username ": "zhangqiang"}]}
Share:
------ Solution --------------------
$ Data = array ();
$ Data ['result'] = array ();
// Any
$ Data ['result'] [] = array ('userid' => '001', 'username': 'lilim ');
In JSON, [] indicates an array, which features no key name and is usually used to represent a value that contains multiple groups of objects. {} Indicates an object, which is characterized by key-value correspondence.
------ Solution --------------------
$ A = array (
'Result' => array (
Array ('userid' => '001', 'username' => 'lilim '),
),
);
Array_pai_recursive ($ a, 'encoding ');
Echo urldecode (json_encode ($ ));
$ A = array (
'Result' => array (
Array ('userid' => '001', 'username' => 'zhangfe '),
Array ('userid' => '001', 'username' => 'zhangfe '),
),
);
Array_pai_recursive ($ a, 'encoding ');
Echo urldecode (json_encode ($ ));
Function encode (& $ item, $ key ){
$ Item = urlencode ($ item );
}
{"Result": [{"userid": "001", "username": "Li Ming"}]}
{"Result": [{"userid": "001", "username": "Zhang Fei" },{ "userid": "001", "username ": "Zhang Fei"}]}