";///one-dimensional array conversion json$arr1 = Array (" username "=" Zhangsan "," Age "=" 1 "); $arr 12Json = Json_encode (;p) Rint_r ($ ARR1); echo "
";p Rint_r ($arr 12Json);//two-dimensional array conversion json$arr2 = Array (" name "=" Zhangsan "," age "=" + "), Array (" name "= > "Lisi", "age" = "+"), $arr 2tojson = Json_encode ($arr 2); echo "
";p Rint_r ($arr 2)."
";; echo "
";p Rint_r ($arr 2tojson);//Convert Objects to JSON (only common variables, private variables and functions not converted) class Demo{public $public _name =" piblic name ";p rotected $ Protected_name = "protected name";p rivate $private _name = "Private name";p ublic function GetName () {return $this->name ;}} $demo = new Demo (); $objToJson = Json_encode ($demo); echo "
";p Rint_r ($demo);p rint_r ($objToJson);? >
Output:
The above describes the conversion of arrays and objects to JSON, including aspects of the content, I hope that the PHP tutorial interested in a friend helpful.