Home > Backend Development > PHP Tutorial > PHP怎么把json字符串转为对象

PHP怎么把json字符串转为对象

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-06-20 12:39:17
Original
1490 people have browsed it

我想把json转化为对象,,,,,,,,,,,,,,求助----PHP 语言 怎么把json字符串转为对象


回复讨论(解决方案)

先把json转数组,然后数组转对象

json_decode($json)  -> 对象
json_decode($json,true)  -> 数组

是这样吗

$array1=array();
$array1=json_decode($json,true) ;
dump($array1);
exit;

有具体的实例吗   

我现在 具体的 JSON 数据已经得到

想把它 转成 对象  传到客户端  方便 JS 解析和查看

那你得在客户端解码

如果要在客户端,可以使用js的JSON.parse()方法来把json字符串转为对象。

  <script type="text/javascript">   var str = '{"type":1}';   var obj = JSON.parse(str);   alert(obj.type);  </script>
Copy after login

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template