Welcome to the Linux community forum and interact with 2 million technical staff to enter json_encode (). This function is mainly used to convert arrays and objects into json format. $ Arrarray (aa, bb, cc, dd, ee); echojson_encode ($ arr); json only accepts UTF-8 encoded characters, json_encode
Welcome to the Linux community forum and interact with 2 million technical staff> enter json_encode (). This function is mainly used to convert arrays and objects into json format. $ Arr = array ('A' = 'A', 'B' = 'B', 'C' = 'C', 'D' = 'D ', 'E' = 'E'); echo json_encode ($ arr); json only accepts UTF-8 encoded characters, json_encode
Welcome to the Linux community forum and interact with 2 million technicians>
Json_encode ()
This function is mainly used to convert arrays and objects to json format.
$ Arr = array ('A' => 'A', 'B' => 'B', 'C' = 'C', 'D' => 'D ', 'E' = 'E ');
Echo json_encode ($ arr );
Json only accepts UTF-8 encoded characters. The json_encode () parameter must be UTF-8 encoded.
Class person
{
Public $ name;
Public $ age;
Public $ height;
Function _ construct ($ name, $ age, $ height)
{
$ This-> name = $ name;
$ This-> age = $ age;
$ This-> height = $ height;
}
}
$ Obj = new person ("zhangsan", 20,100 );
$ Foo_json = json_encode ($ obj );
Echo $ foo_json;
When the attribute in the class is a private variable, it is not output.
Json_decode ()
This function is used to convert json text to the corresponding PHP data structure.
$ Json = '{"a": "hello", "B": "world", "c": "zhangsan", "d": 20, "e ": 170 }';
Var_dump (json_decode ($ json ));
In general, json_decode () always returns a PHP Object.
Convert to an array:
$ Json = '{"a": "hello", "B": "world", "c": "zhangsan", "d": 20, "e ": 170 }';
Var_dump (json_decode ($ json, ture ));