<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
 <html>
  <head>
   <title> json_encode.php </title>
   <meta charset="UTF-8">
   <meta name="Author" content="">
   <meta name="Keywords" content="">
   <meta name="Description" content="">
  </head> <body>
 <?php
 $arr = array ('a'=>1,'b'=>2,'c'=>3,'d'=>4,'e'=>5);
 var_dump($arr);
 echo json_encode($arr);
 ?>
 <hr>
 <?php
 $obj->body           = 'another post';
 $obj->id             = 21;
 $obj->approved       = true;
 $obj->favorite_count = 1;
 $obj->status         = NULL;
 var_dump($obj);
 echo json_encode($obj);
 ?>
 <hr>
 <?php
 $arr = Array('one', 'two', 'three');
 echo json_encode($arr);
 //结果为:
 //["one","two","three"] 
 //如果将它改为关联数组:
 $arr = Array('1'=>'one', '2'=>'two', '3'=>'three');
 echo json_encode($arr);
 ?>
 <hr>
 <?php
 $json = '{"foo": 12345}';
 $obj = json_decode($json);
 print $obj->{'foo'}; // 12345
 ?>
 <hr>
  </body>
 </html>
 
array
  'a' => int 1
  'b' => int 2
  'c' => int 3
  'd' => int 4
  'e' => int 5
 
{"a":1,"b":2,"c":3,"d":4,"e":5}
object(stdClass)[1]
  public 'body' => string 'another post' (length=12)
  public 'id' => int 21
  public 'approved' => boolean true
  public 'favorite_count' => int 1
  public 'status' => null
 
{"body":"another post","id":21,"approved":true,"favorite_count":1,"status":null}
["one","two","three"]{"1":"one","2":"two","3":"three"}

12345