<?php
- $array _1 = Array (); One-dimensional arrays
- $array _2 = Array (); Two-dimensional array
- $array _1[' username '] = "Aseoe";
- $array _1[' website '] = "http://www.aseoe.com/";
- $array _2[' member ' [' ancto.net '] [' username '] = "ancto";
- $array _2[' member ' [' ancto.net '] [' website '] = "http://www.ancto.net/";
- $array _2[' member ' [' aseoe.com '] [' username '] = "Aseoe";
- $array _2[' member ' [' aseoe.com '] [' website '] = "http://www.aseoe.com/";
- Print_r ($array _2);
- $JSONOBJ _1 = Json_encode ($array _1); One-dimensional array into JSON data format
- echo $JSONOBJ _1;
- $JSONOBJ _2 = Json_encode ($array _2); Multidimensional array converted to JSON data format
- echo $JSONOBJ _2;
- Class aseoe{
- Public $puname = ' public name ';
- Protected $poname = "protected name";
- Private $prname = "private Name";
- Public Function GetName () {
- return $this->name;
- }
- }
- $ASEOEOBJ = new Aseoe ();
- $json _aseoe =json_encode ($ASEOEOBJ); object into JSON data format
- echo $json _aseoe; object is converted to JSON data, only public variables are converted, and private variables are not converted
- Print_r ($ASEOEOBJ);
- $jsonStr = ' {' key ': ' Value ', ' key1 ': ' value2 '} ';
- $json 2Array = Json_decode ($jsonStr, true); The default is object type when no 2nd argument is set
- Print_r ($json 2Array);
$jsonStr = ' {' key ': ' Value ', ' key1 ': ' value1 '} '; Json_decode ($JSONSTR);//After conversion is the object type Json_decode ($jsonStr, true);//After conversion is an array