• 欢迎访问搞代码网站,推荐使用最新版火狐浏览器和Chrome浏览器访问本网站!
  • 如果您觉得本站非常有看点,那么赶紧使用Ctrl+D 收藏搞代码吧

json数据解析返回为空,哪里出有关问题了

php 搞代码 4年前 (2022-01-24) 23次浏览 已收录 0个评论

json数据解析返回为空,哪里出问题了?
事情是这样的:

A网站提供一个连接接口,我验证登录信息通过后,返回一个json数据;但是我用$response = json_decode($output);却得不到数据、返回是空; 请教坛子里高手,怎么才能正确解析json数据成数组呢 、
数据部分截取:

PHP code

<!---ecms Code highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/-->{"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}]}

我的代码是这样的:

PHP code

<!---ecms Code highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/--><?phpheader ("Content-Type:text/html; charset=UTF-8");  $url = 'http://58.61.153.173/dataport/GetAllTourInfo.ashx';$host=array('user: admin','password: admin_123');$ch = curl_init();curl_setopt($ch, CURLOPT_URL, $url);curl_setopt($ch, CURLOPT_HEADER, 0);curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);curl_setopt($ch,CURLOPT_HTTPHEADER,$host);$output = curl_exec($ch);print $output; //数据能打印出来,如上面那数据$response = json_decode($output);//加上后边这两句,也不报错、但是也没有数据打印出来print $response;//加上后边这两句,也不报错、但是也没有数据打印出来?>

——解决方案——————–
因为
“StartDate”:new Date(1350691200000),
造成的,把它从字符串中都拿掉就可以了.你试试,我刚才调试过试验了.
——解决方案——————–

PHP code

$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] =>来4源gaodaimacom搞#代%码*网搞代gaodaima码 儿童图书教系列                    [ProcessDays] => 1                    [ProcessResume] =>                     [WorkDayPrice] => 79                    [WeekdayPrice] => 89                    [NormalPrice] => 0                    [Catalog] => 0                    [Type] => 0                    [RDCatalog] => 0                    [BizCatalog] => 0                    [StartDate] => new Date(1350777600000)                    [Deleted] => 0                )        ))*/ 


搞代码网(gaodaima.com)提供的所有资源部分来自互联网,如果有侵犯您的版权或其他权益,请说明详细缘由并提供版权或权益证明然后发送到邮箱[email protected],我们会在看到邮件的第一时间内为您处理,或直接联系QQ:872152909。本网站采用BY-NC-SA协议进行授权
转载请注明原文链接:json数据解析返回为空,哪里出有关问题了
喜欢 (0)
[搞代码]
分享 (0)
发表我的评论
取消评论

表情 贴图 加粗 删除线 居中 斜体 签到

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址