轻源码

  • QingYuanMa.com
  • 全球最大的互联网技术和资源下载平台
搜索
一起源码网 门户 前端设计 查看主题

json数据格式的相互转换

发布者: soundbear | 发布时间: 2018-1-29 01:47| 查看数: 2265| 评论数: 1|帖子模式


<?php 
  1.  
  2.     $array_1 = array();  //一维数组 
  3.     $array_2 = array();  //二维数组 
  4.  
  5.     $array_1['username'] = "Aseoe"
  6.     $array_1['website'] = ""
  7.  
  8.     $array_2['member']['ancto.net']['username'] = "ancto"
  9.     $array_2['member']['ancto.net']['website'] = "
  10.  
  11.     $array_2['member']['aseoe.com']['username'] = "aseoe"
  12.     $array_2['member']['aseoe.com']['website'] = ""
  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);//转换之后是数组 

 


 

true json数据格式的相互转换 show-12-467-1.html report 3201 <?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;][

最新评论

xiAoT 发表于 2022-5-15 17:03
音乐下载网站免费mp3

轻源码让程序更轻更快

QingYuanMa.com

工作时间 周一至周六 8:00-17:30

侵权处理

客服QQ点击咨询

关注抖音号

定期抽VIP

Copyright © 2016-2021 https://www.171739.xyz/ 滇ICP备13200218号

快速回复 返回顶部 返回列表