Home  >  Article  >  Backend Development  >  json如何解码成数组输出

json如何解码成数组输出

WBOY
WBOYOriginal
2016-06-13 13:22:16863browse

json怎么解码成数组输出?
a:2:{i:0;s:21:"www";i:1;s:16:"eee";}

------解决方案--------------------
看json_decode

http://php.net/manual/en/function.json-decode.php


------解决方案--------------------
你确认这是一个正确的Json格式数据?
------解决方案--------------------
数据库里的数据是哪来的?我想他不应该是Json...

探讨

引用:

你确认这是一个正确的Json格式数据?

同问
数据库就这样的!
json_decode 用过数组就一个值。

------解决方案--------------------
象serialize的, 
不过还是有点小奇怪
------解决方案--------------------
我测试过,无法正常还原的

探讨

象serialize的,
不过还是有点小奇怪

------解决方案--------------------
这分明不是json
------解决方案--------------------
有cms uchome好像这么储存过数据
------解决方案--------------------
先在这个http://jsonlint.com/ 验证下json格式是否正确,json转换成数组的话用 json_decode
------解决方案--------------------
读出来是这个 array('www','eee'); 但是数组元素的长度不正确
------解决方案--------------------
看这格式不是json,是serialize序列化之后的结果,但数据明显有问题

a:2:{i:0;s:21:"www";i:1;s:16:"eee";};

意思是:一个数组包含两个元素,第一个元素是长为21的字符串www(明显不对,长度应该是3),第二个元素是长为16的字符串eee(也不对)

$str='a:2:{i:0;s:3:"www";i:1;s:3:"eee";}';
var_dump(unserialize($str));
//这应该就对了
------解决方案--------------------
array(2) { [0]=> string(3) "www" [1]=> string(3) "eee" }
Statement:
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