json数据格式的相互转换

导语 <?php$array_1=array(); 一维数组$array_2=array(); 二维数组$array_1[& 39;username& 39;]="Aseoe";$array_1[& 39;website& 39;]="http: www aseoe com ";$array_2[& 39;member& 39;][& 39;ancto net& 39;][

<?php 
  1.  
  2.     $array_1 = array();  //一维数组 
  3.     $array_2 = array();  //二维数组 
  4.  
  5.     $array_1['username'] = "Aseoe"; 
  6.     $array_1['website'] = "http://www.aseoe.com/"; 
  7.  
  8.     $array_2['member']['ancto.net']['username'] = "ancto"; 
  9.     $array_2['member']['ancto.net']['website'] = "http://www.ancto.net/"; 
  10.  
  11.     $array_2['member']['aseoe.com']['username'] = "aseoe"; 
  12.     $array_2['member']['aseoe.com']['website'] = "http://www.aseoe.com/"; 
  13.  
  14.     //print_r($array_2); 
  15.  
  16.     $jsonObj_1 = json_encode($array_1);  //一维数组转换成json数据格式 
  17.     //echo $jsonObj_1; 
  18.  
  19.     $jsonObj_2 = json_encode($array_2);     //多维数组转换成json数据格式 
  20.     //echo $jsonObj_2; 
  21.  
  22.     class aseoe{ 
  23.         public $puname = "public name"; 
  24.         protected $poname = "protected name"; 
  25.         private $prname = "private name"; 
  26.  
  27.         public function getName(){ 
  28.             return $this->name; 
  29.         } 
  30.  
  31.     } 
  32.  
  33.     $aseoeObj = new aseoe(); 
  34.     $json_aseoe =json_encode($aseoeObj);    //对象转换成json数据格式 
  35.     //echo $json_aseoe;    //对象转换为json数据时,只转换公有变量,私有变量不转换 
  36.  
  37.     //print_r($aseoeObj); 
  38.  
  39.     $jsonStr = '{"key":"value","key1":"value2"}'; 
  40.     $json2Array = json_decode($jsonStr,true);  //没设第2个参数时,默认是对象类型 
  41.     print_r($json2Array); 

 

$jsonStr='{"key":"value","key1":"value1"}'; 
 
json_decode($jsonStr);//转换之后是对象类型 
 
json_decode($jsonStr,true);//转换之后是数组 

 


 

http://www.aseoe.com/ true json数据格式的相互转换 http://www.aseoe.com/show-12-467-1.html report <?php echo strlen($content) / 2; ?> <?php$array_1=array(); 一维数组$array_2=array(); 二维数组$array_1[& 39;username& 39;]="Aseoe";$array_1[& 39;website& 39;]="http: www aseoe com ";$array_2[& 39;member& 39;][& 39;ancto net& 39;][
TAG:json 格式数据
本站欢迎任何形式的转载,但请务必注明出处,尊重他人劳动成果
转载请注明: 文章转载自:爱思资源网 http://www.aseoe.com/show-12-467-1.html

[前端插件推荐] Plugin

1 2 3 4
  • jQuery实现逐字逐句显示插件l-by-l.min.js
  • jQuery带方向感知的鼠标滑过图片边框特效插件
  • jQuery HotKeys监听键盘按下事件keydown插件
  • 响应式无限轮播jQuery旋转木马插件
响应式无限轮播jQuery旋转木马插件
web前端开发
爱思资源网 Copyright 2012-2014 Www.Aseoe.Com All rights reserved.(晋ICP备13001436号-1)