怎么这样的json解析不了?

liujianliang 2011-12-22 09:48:34
这个数据是从后台程序返回的{"bool":"1","string":"\u6dfb\u52a0\u6210\u529f"}
从结构上没有什么不妥,但是用json_deconde解析不了
...全文
251 11 打赏 收藏 转发到动态 举报
写回复
用AI写文章
11 条回复
切换为时间正序
请发表友善的回复…
发表回复
睡梦之龙 2011-12-22
  • 打赏
  • 举报
回复
这个json用的都是单引号括起来的,这个返回来的是双引号,弄起来还是比较麻烦的.
你先把里面双引号转成单引号再转换吧.
xuzuning 2011-12-22
  • 打赏
  • 举报
回复
复制你#2的
{"bool":"1","string":"\u6dfb\u52a0\u6210\u529f"}
到 textarea 变成
{"bool":"1","string":"\u6dfb\u52a0\u6210\u529f"}

你说前面多出的是什么?
liujianliang 2011-12-22
  • 打赏
  • 举报
回复
[Quote=引用 7 楼 ci1699 的回复:]
$result=Sync::httppost($url,$postData);
echo $result;exit();

查看源文件贴上来啊。。。


引用 6 楼 liujianliang 的回复:

引用 5 楼 xuzuning 的回复:
{"bool":"1","string":"\u6dfb\u52a0\u6210\u529f"}
的长度是 48
而你 var_d……
[/Quote]
页面输出以下文字
{"bool":"1","string":"\u6dfb\u52a0\u6210\u529f"}
ci1699 2011-12-22
  • 打赏
  • 举报
回复

$result=Sync::httppost($url,$postData);
echo $result;exit();

查看源文件贴上来啊。。。

[Quote=引用 6 楼 liujianliang 的回复:]

引用 5 楼 xuzuning 的回复:
{"bool":"1","string":"\u6dfb\u52a0\u6210\u529f"}
的长度是 48
而你 var_dump($result) 的结果是 51

多出的 3 个字节是什么呢?
显然是 BOM 头

是dw检查了一遍,没发现包含bom
[/Quote]
liujianliang 2011-12-22
  • 打赏
  • 举报
回复
[Quote=引用 5 楼 xuzuning 的回复:]
{"bool":"1","string":"\u6dfb\u52a0\u6210\u529f"}
的长度是 48
而你 var_dump($result) 的结果是 51

多出的 3 个字节是什么呢?
显然是 BOM 头
[/Quote]
是dw检查了一遍,没发现包含bom
xuzuning 2011-12-22
  • 打赏
  • 举报
回复
{"bool":"1","string":"\u6dfb\u52a0\u6210\u529f"}
的长度是 48
而你 var_dump($result) 的结果是 51

多出的 3 个字节是什么呢?
显然是 BOM 头
ci1699 2011-12-22
  • 打赏
  • 举报
回复
应该是被转义了。
$result=Sync::httppost($url,$postData);
echo $result;exit(); 看下是什么。

[Quote=引用 3 楼 liujianliang 的回复:]

纠正一下,上面写错了
$result=Sync::httppost($url,$postData);
$resultArray=json_decode($result,true);
var_dump($result);
var_dump($resultArray);
结果为:
string(51) "{"bool":"1","string":"\u6dfb\u52a0\u6210……
[/Quote]
liujianliang 2011-12-22
  • 打赏
  • 举报
回复
纠正一下,上面写错了
$result=Sync::httppost($url,$postData);
$resultArray=json_decode($result,true);
var_dump($result);
var_dump($resultArray);
结果为:
string(51) "{"bool":"1","string":"\u6dfb\u52a0\u6210\u529f"}"
NULL
liujianliang 2011-12-22
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 ohmygirl 的回复:]
PHP code
<?php
$json = '{"bool":"1","string":"\u6dfb\u52a0\u6210\u529f"}';
$arr = json_decode($json,true);
print_r($arr);
//Array ( [bool] => 1 [string] => 添加成功 ) ;
[/Quote]
用这种方式的确可以。我是用curl post的方式提交并获取返回值的
$result=Sync::httppost($url,$postData);
$resultArray=json_decode('$result',true);
var_dump($result);
var_dump($resultArray);
结果为:
string(51) "{"bool":"1","string":"\u6dfb\u52a0\u6210\u529f"}"
NULL
ohmygirl 2011-12-22
  • 打赏
  • 举报
回复
<?php
$json = '{"bool":"1","string":"\u6dfb\u52a0\u6210\u529f"}';
$arr = json_decode($json,true);
print_r($arr);
//Array ( [bool] => 1 [string] => 添加成功 ) ;
cxm709645492 2011-12-22
  • 打赏
  • 举报
回复
....差2分...

21,886

社区成员

发帖
与我相关
我的任务
社区描述
从PHP安装配置,PHP入门,PHP基础到PHP应用
社区管理员
  • 基础编程社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧