The returned result of json data parsing is null. what is the problem? This is the case: Website A provides A connection interface. After I verify that the logon information is passed, A json data is returned, but I use $ response = json_decode ($ output ); however, no data is available and the returned result is empty. how can I parse json data into an array correctly and truncate the data in part? PHPcode {json data is parsed and returned as null?
The problem is as follows:
Website A provides A connection interface. After I verify that the logon information is passed, A json data is returned. However, I use $ response = json_decode ($ output), but I cannot get the data and the returned result is empty; how can I parse json data into arrays,
Partial data truncation:
PHP code
{"Total": 359, "data": [{"Id": 113023, "ProductId": 2905, "ProductCode": "SZX01", "ProductName ": "Computer Book Series", "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": "Children's Books series", "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}]}
My code is as follows:
PHP code
------ Solution --------------------
Because
"StartDate": new Date (1350691200000 ),
The result is that you can remove it from the string. you try it. I tested it just now.
------ Solution --------------------
PHP code
$ S = '{"total": 359, "data": [{"Id": 113023, "ProductId": 2905, "ProductCode": "SZX01 ", "ProductName": "Computer Book Series", "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": "children's book series ", "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] => computer book series [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] => children's book series [ProcessDays] => 1 [ProcessResume] => [WorkDayPrice] => 79 [WeekdayPrice] => 89 [NormalPrice] => 0 [Catalog] => 0 [Type] => 0 [RDCatalog] => 0 [BizCatalog] => 0 [StartDate] => new Date (1350777600000) [Deleted] => 0 )))*/