백엔드 개발 PHP 튜토리얼 json数据解析返回为空,哪里出有关问题了

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

Jun 13, 2016 pm 01:07 PM
gt quot

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

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

PHP code
<!--

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
<!--

Code highlighting produced by Actipro CodeHighlighter (freeware)
http://www.CodeHighlighter.com/

-->

<?php header ("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] =&gt; 359
    [data] =&gt; Array
        (
            [0] =&gt; stdClass Object
                (
                    [Id] =&gt; 113023
                    [ProductId] =&gt; 2905
                    [ProductCode] =&gt; SZX01
                    [ProductName] =&gt; 计算机图书系列
                    [ProcessDays] =&gt; 1
                    [ProcessResume] =&gt; 
                    [WorkDayPrice] =&gt; 79
                    [WeekdayPrice] =&gt; 89
                    [NormalPrice] =&gt; 0
                    [Catalog] =&gt; 0
                    [Type] =&gt; 0
                    [RDCatalog] =&gt; 0
                    [BizCatalog] =&gt; 0
                    [StartDate] =&gt; new Date(1350691200000)
                    [Deleted] =&gt; 0
                )

            [1] =&gt; stdClass Object
                (
                    [Id] =&gt; 113024
                    [TourId] =&gt; 2905
                    [ProductCode] =&gt; SZX01
                    [ProductName] =&gt; 儿童图书教系列
                    [ProcessDays] =&gt; 1
                    [ProcessResume] =&gt; 
                    [WorkDayPrice] =&gt; 79
                    [WeekdayPrice] =&gt; 89
                    [NormalPrice] =&gt; 0
                    [Catalog] =&gt; 0
                    [Type] =&gt; 0
                    [RDCatalog] =&gt; 0
                    [BizCatalog] =&gt; 0
                    [StartDate] =&gt; new Date(1350777600000)
                    [Deleted] =&gt; 0
                )

        )

)
*/
 <div class="clear">
                 
              
              
        
            </div>
로그인 후 복사
본 웹사이트의 성명
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.

뜨거운 기사 태그

메모장++7.3.1

메모장++7.3.1

사용하기 쉬운 무료 코드 편집기

SublimeText3 중국어 버전

SublimeText3 중국어 버전

중국어 버전, 사용하기 매우 쉽습니다.

스튜디오 13.0.1 보내기

스튜디오 13.0.1 보내기

강력한 PHP 통합 개발 환경

드림위버 CS6

드림위버 CS6

시각적 웹 개발 도구

SublimeText3 Mac 버전

SublimeText3 Mac 버전

신 수준의 코드 편집 소프트웨어(SublimeText3)

화웨이 GT3 Pro와 GT4의 차이점은 무엇입니까? 화웨이 GT3 Pro와 GT4의 차이점은 무엇입니까? Dec 29, 2023 pm 02:27 PM

화웨이 GT3 Pro와 GT4의 차이점은 무엇입니까?

수정: Windows 11에서 캡처 도구가 작동하지 않음 수정: Windows 11에서 캡처 도구가 작동하지 않음 Aug 24, 2023 am 09:48 AM

수정: Windows 11에서 캡처 도구가 작동하지 않음

iPhone에서 App Store 오류에 연결할 수 없는 문제를 해결하는 방법 iPhone에서 App Store 오류에 연결할 수 없는 문제를 해결하는 방법 Jul 29, 2023 am 08:22 AM

iPhone에서 App Store 오류에 연결할 수 없는 문제를 해결하는 방법

php提交表单通过后,弹出的对话框怎样在当前页弹出,该如何解决 php提交表单通过后,弹出的对话框怎样在当前页弹出,该如何解决 Jun 13, 2016 am 10:23 AM

php提交表单通过后,弹出的对话框怎样在当前页弹出,该如何解决

watch4pro가 더 나은가요, 아니면 gt인가요? watch4pro가 더 나은가요, 아니면 gt인가요? Sep 26, 2023 pm 02:45 PM

watch4pro가 더 나은가요, 아니면 gt인가요?

iPadOS 17.4로 iPad 배터리 수명을 최적화하는 방법 iPadOS 17.4로 iPad 배터리 수명을 최적화하는 방법 Mar 21, 2024 pm 10:31 PM

iPadOS 17.4로 iPad 배터리 수명을 최적화하는 방법

Guan Zeyuanjiang Shuying은 기술과 예술의 완벽한 결합인 Huawei MateBook GT 14를 경험합니다. Guan Zeyuanjiang Shuying은 기술과 예술의 완벽한 결합인 Huawei MateBook GT 14를 경험합니다. Aug 10, 2024 pm 09:51 PM

Guan Zeyuanjiang Shuying은 기술과 예술의 완벽한 결합인 Huawei MateBook GT 14를 경험합니다.

不用数据库来实现用户的简单的下载,代码如下,但是却不能下载,请高手找下原因,文件路劲什么的没有关问题 不用数据库来实现用户的简单的下载,代码如下,但是却不能下载,请高手找下原因,文件路劲什么的没有关问题 Jun 13, 2016 am 10:15 AM

不用数据库来实现用户的简单的下载,代码如下,但是却不能下载,请高手找下原因,文件路劲什么的没有关问题

See all articles