Home > Backend Development > PHP Tutorial > 接口传过去的值,别人解析

接口传过去的值,别人解析

WBOY
Release: 2016-06-23 13:37:57
Original
995 people have browsed it

??{	"status":"ok",	"msg":"登录成功!",	"data":[		{			"uid":"27",			"username":"123",			"password":"202cb962ac59075b964b07152d234b70",			"nickname":"aaa",			"telephone":"",			"phone":null,			"qq":"",			"fax":null,			"email":"",			"department":"",			"job":null,			"seniority":"0",			"integral":"10",			"strength":null,			"ip":null,			"time":null		}	]}
Copy after login



不知道是不是我这json格式错了?


回复讨论(解决方案)

1、有多个 BOM 头
2、null 也要用双引号括起来

print_r(json_decode($s));
解码后

stdClass Object(    [status] => ok    [msg] => 登录成功!    [data] => Array        (            [0] => stdClass Object                (                    [uid] => 27                    [username] => 123                    [password] => 202cb962ac59075b964b07152d234b70                    [nickname] => aaa                    [telephone] =>                     [phone] => null                    [qq] =>                     [fax] => null                    [email] =>                     [department] =>                     [job] => null                    [seniority] => 0                    [integral] => 10                    [strength] => null                    [ip] => null                    [time] => null                )        ))
Copy after login
Copy after login
Copy after login


1、有多个 BOM 头
2、null 也要用双引号括起来

print_r(json_decode($s));
解码后

stdClass Object(    [status] => ok    [msg] => 登录成功!    [data] => Array        (            [0] => stdClass Object                (                    [uid] => 27                    [username] => 123                    [password] => 202cb962ac59075b964b07152d234b70                    [nickname] => aaa                    [telephone] =>                     [phone] => null                    [qq] =>                     [fax] => null                    [email] =>                     [department] =>                     [job] => null                    [seniority] => 0                    [integral] => 10                    [strength] => null                    [ip] => null                    [time] => null                )        ))
Copy after login
Copy after login
Copy after login



我发现哪里错了。。 json格式应该是没错。。
但是我的json第一个大括号错了。。 我在JSONLint 检验了一下。 我把我的大括号删了重新输入。就正确了
这个是因为什么啊? 我用同样的查询语句。。有的可以,有的不行。。
而且文件编码都是utf-8

推荐一个网站给你检测一下你的json数据格式吧, http://bejson.com

bejson正解

1、有多个 BOM 头
2、null 也要用双引号括起来

print_r(json_decode($s));
解码后

stdClass Object(    [status] => ok    [msg] => 登录成功!    [data] => Array        (            [0] => stdClass Object                (                    [uid] => 27                    [username] => 123                    [password] => 202cb962ac59075b964b07152d234b70                    [nickname] => aaa                    [telephone] =>                     [phone] => null                    [qq] =>                     [fax] => null                    [email] =>                     [department] =>                     [job] => null                    [seniority] => 0                    [integral] => 10                    [strength] => null                    [ip] => null                    [time] => null                )        ))
Copy after login
Copy after login
Copy after login



我明白了 。。 是多个bom头 的问题。。测试了好久。。终于弄明白了。。
膜拜啊。。今天又学了一招。。
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