猿问

php 处理json字符串的问题?

php 处理json字符串的问题


湖上湖
浏览 700回答 2
2回答

慕姐8265434

123456<?php$json&nbsp;=&nbsp;'{"a":1,"b":2,"c":3,"d":4,"e":5}';$jsonArr&nbsp;=&nbsp;json_decode($json,&nbsp;TRUE);extract($jsonArr);&nbsp;//数组中将变量导入到以当前符号表echo&nbsp;"a=$a;b=$b;c=$c;d=$d;e=$e;";?>另外也可以像遍历数组一样遍历得到的对象。123456789<?php$json&nbsp;=&nbsp;'{"a":1,"b":2,"c":3,"d":4,"e":5}';$jsonObj&nbsp;=&nbsp;json_decode($json);foreach($jsonObj&nbsp;as&nbsp;$jk=>$jv)&nbsp;{&nbsp;&nbsp;&nbsp;&nbsp;$$jk&nbsp;=&nbsp;$jv;}echo&nbsp;"a=$a;b=$b;c=$c;d=$d;e=$e;";//也可得到相同的结果?>&nbsp;另外通过json_decode获得的json对象,也可以通过"$jsonObj->a"这样的方式获取其值。

海绵宝宝撒

$c&nbsp;=&nbsp;json_decode($json);echo&nbsp;$c->a;值是这样获取object的值123456$json&nbsp;=&nbsp;'{"a":1,"b":2,"c":3,"d":4,"e":5}';$c&nbsp;=&nbsp;json_decode($json);$f&nbsp;=&nbsp;get_object_vars($c);//转换为数组foreach($f&nbsp;as&nbsp;$k=>$v){&nbsp;&nbsp;&nbsp;&nbsp;echo&nbsp;$k."=".$v."<br&nbsp;/>";}
随时随地看视频慕课网APP

相关分类

Java
我要回答