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

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

WBOY
Release: 2016-06-23 14:28:02
Original
888 people have browsed it

//这正常<?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"加引号可以吗"}
Copy after login


回复讨论(解决方案)

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

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

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