Home >Backend Development >PHP Tutorial >php前辈请进来,求个双引号和单引号问题

php前辈请进来,求个双引号和单引号问题

WBOY
WBOYOriginal
2016-06-23 14:28:02904browse

//这正常<?php$json = '{"foo":12345999}'; $obj = json_decode($json);echo $obj->{'foo'}?>//不正常<?php$json = '{foo:"12345999"}'; $obj = json_decode($json);echo $obj->{'foo'}?>//-------------{foo:"因我取到js串就是这样,能否直接用,不给"foo"加引号可以吗"}


回复讨论(解决方案)

不可以
作为 js 的对象,加不加都可以(新标准是必须加)
作为 json 则必须加,否则 son_decode 不认识

必须要满足json格式标准,不然解析会出问题。

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