json数据解析返回为空,哪里出问题了? 本帖最后由 pankay 于 2012-10-19 22:20:07 编辑 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 因为"StartDate":new Date(1350691200000),造成的,把它从字符串中都拿掉就可以了.你试试,我刚才调试过试验了. 你也是 用 $data = json_decode($output);print($data);这样吗? 这个也试了,打印无数据、头部是不是要加 包含什么json类或者对象文件 ? $s='{"total":359,"data":[{"Id":113023,"ProductId":2905,"ProductCode":"SZX01","ProductName":"计算机图书系列","ProcessDays":1,"ProcessResume":"","WorkDayPrice":79.0000,"WeekdayPrice":89.0000,"NormalPrice":0.0000,"Catalog":"0","Type":0,"RDCatalog":0,"BizCatalog":0,"StartDate":new Date(1350691200000),"Deleted":0},{"Id":113024,"TourId":2905,"ProductCode":"SZX01","ProductName":"儿童图书教系列","ProcessDays":1,"ProcessResume":"","WorkDayPrice":79.0000,"WeekdayPrice":89.0000,"NormalPrice":0.0000,"Catalog":"0","Type":0,"RDCatalog":0,"BizCatalog":0,"StartDate":new Date(1350777600000),"Deleted":0}]}';$s=preg_replace('/new Date[^,]+/','"$0"',$s);print_r(json_decode($s));/*stdClass Object( [total] => 359 [data] => Array ( [0] => stdClass Object ( [Id] => 113023 [ProductId] => 2905 [ProductCode] => SZX01 [ProductName] => 计算机图书系列 [ProcessDays] => 1 [ProcessResume] => [WorkDayPrice] => 79 [WeekdayPrice] => 89 [NormalPrice] => 0 [Catalog] => 0 [Type] => 0 [RDCatalog] => 0 [BizCatalog] => 0 [StartDate] => new Date(1350691200000) [Deleted] => 0 ) [1] => stdClass Object ( [Id] => 113024 [TourId] => 2905 [ProductCode] => SZX01 [ProductName] => 儿童图书教系列 [ProcessDays] => 1 [ProcessResume] => [WorkDayPrice] => 79 [WeekdayPrice] => 89 [NormalPrice] => 0 [Catalog] => 0 [Type] => 0 [RDCatalog] => 0 [BizCatalog] => 0 [StartDate] => new Date(1350777600000) [Deleted] => 0 ) ))*/ 我也测试理下,是new Date(1350691200000)这里有问题。加上双引号就可以了。$str = '{"total":359,"data":[{"Id":113023,"ProductId":2905,"ProductCode":"SZX01","ProductName":"计算机图书系列","ProcessDays":1,"ProcessResume":"","WorkDayPrice":79.0000,"WeekdayPrice":89.0000,"NormalPrice":0.0000,"Catalog":"0","Type":0,"RDCatalog":0,"BizCatalog":0,"StartDate":"new Date(1350691200000)","Deleted":0},{"Id":113024,"TourId":2905,"ProductCode":"SZX01","ProductName":"儿童图书教系列","ProcessDays":1,"ProcessResume":"","WorkDayPrice":79.0000,"WeekdayPrice":89.0000,"NormalPrice":0.0000,"Catalog":"0","Type":0,"RDCatalog":0,"BizCatalog":0,"StartDate":"new Date(1350777600000)","Deleted":0}]}'; 后来我让网站A方修改了startDate的字段格式,用json_decode就解析成功了、、问题解决了,很开心,谢谢大家的建议、 更新数据的判断 phper进来看看 Linux下的php开发,路径问题 关于变量的一个小问题! 有没有php+sybase的分页的参考代码?100分相赠 求救!为什么用在smarty 模板里的JavaScript脚本都无法使用呢? php怎么比较两个日期的大小? 请问,函数 file_get_contents( ) 问今天遇到的两个问题??? 在客服端抓取服务器本地的url怎么提高速度?? PHP 用继承 _contruct()出问题 "ENTP" "ISTP"这2个字符串怎么单个字符进行比较?
"StartDate":new Date(1350691200000),
造成的,把它从字符串中都拿掉就可以了.你试试,我刚才调试过试验了.
$s=preg_replace('/new Date[^,]+/','"$0"',$s);
print_r(json_decode($s));
/*
stdClass Object
(
[total] => 359
[data] => Array
(
[0] => stdClass Object
(
[Id] => 113023
[ProductId] => 2905
[ProductCode] => SZX01
[ProductName] => 计算机图书系列
[ProcessDays] => 1
[ProcessResume] =>
[WorkDayPrice] => 79
[WeekdayPrice] => 89
[NormalPrice] => 0
[Catalog] => 0
[Type] => 0
[RDCatalog] => 0
[BizCatalog] => 0
[StartDate] => new Date(1350691200000)
[Deleted] => 0
) [1] => stdClass Object
(
[Id] => 113024
[TourId] => 2905
[ProductCode] => SZX01
[ProductName] => 儿童图书教系列
[ProcessDays] => 1
[ProcessResume] =>
[WorkDayPrice] => 79
[WeekdayPrice] => 89
[NormalPrice] => 0
[Catalog] => 0
[Type] => 0
[RDCatalog] => 0
[BizCatalog] => 0
[StartDate] => new Date(1350777600000)
[Deleted] => 0
) ))
*/
加上双引号就可以了。$str = '{"total":359,"data":[{"Id":113023,"ProductId":2905,"ProductCode":"SZX01","ProductName":"计算机图书系列","ProcessDays":1,"ProcessResume":"","WorkDayPrice":79.0000,"WeekdayPrice":89.0000,"NormalPrice":0.0000,"Catalog":"0","Type":0,"RDCatalog":0,"BizCatalog":0,"StartDate":"new Date(1350691200000)","Deleted":0},{"Id":113024,"TourId":2905,"ProductCode":"SZX01","ProductName":"儿童图书教系列","ProcessDays":1,"ProcessResume":"","WorkDayPrice":79.0000,"WeekdayPrice":89.0000,"NormalPrice":0.0000,"Catalog":"0","Type":0,"RDCatalog":0,"BizCatalog":0,"StartDate":"new Date(1350777600000)","Deleted":0}]}';