Why can't I open json data? _ (: invalid "invalid )_

Source: Internet
Author: User
Why can't I close json data? _ (: invalid "response) _ http: // 202.103.244.125/catst. php
As mentioned above, PHP is so anxious! Json_decode always comes out of null !!! I have tried all the methods on the internet. please help me.


Reply to discussion (solution)

I don't believe you have tried it.

$url = 'http://202.103.244.125/catst.php';$s = file_get_contents($url);print_r(json_decode(substr($s, 3)));
Array ([0] => stdClass Object ([menutype] => A [groupx] => 0 [titleng] => Dish [titlech] => Cold Dish) [1] => stdClass Object ([menutype] => A [groupx] => 1 [titleng] => Soup Porrdg) [2] => stdClass Object ([menutype] => A [groupx] => 2 [titleng] => Hot food [titlech] => Hot food) [3] => stdClass Object ([menutype] => A [groupx] => 3 [titleng] => vegetarian dishes [titlech] => Veget-able) [4] => stdClass Object ([menutype] => A [groupx] => 4 [titleng] => staple Food [titlech] => Main Food) [5] => stdClass Object ([menutype] => A [groupx] => 5 [titleng] => grilled fish beer fish [titlech] => grilled fish beer fish) [6] => stdClass Object ([menutype] => A [groupx] => 6 [titleng] => dry pot [titlech] => Gangou Hotpot) [7] => stdClass Object ([menutype] => A [groupx] => 7 [titleng] => titlech [titlech] => Sheet Hotpot) [8] => stdClass Object ([menutype] => A [groupx] => 8 [titleng] => casserole [titlech] => Sha Guo) [9] => stdClass Object ([menutype] => A [groupx] => 9 [titleng] => [titlech] =>) [10] => stdClass Object ([menutype] => A [groupx] => 10 [titleng] => [titlech] => Special Food) [11] => stdClass Object ([menutype] => A [groupx] => 11 [titleng] => 18 brewed [titlech] => 18 brewed) [12] => stdClass Object ([menutype] => A [groupx] => 12 [titleng] => beverage Tea [titlech] => Drink Tea) [13] => stdClass Object ([menutype] => A [groupx] => 13 [titleng] => other custom [titlech] => other custom) [14] => stdClass Object ([menutype] => A [groupx] => 14 [titleng] => liquor Beer [titlech] => Wine Beer ))

Get a BOM header to harm yourself

Http: // 202.103.244.125/catst. php
As mentioned above, PHP is so anxious! Json_decode always comes out of null !!! I have tried all the methods on the internet. please help me.


Positive solution

I don't believe you have tried it.

$url = 'http://202.103.244.125/catst.php';$s = file_get_contents($url);print_r(json_decode(substr($s, 3)));
Array ([0] => stdClass Object ([menutype] => A [groupx] => 0 [titleng] => Dish [titlech] => Cold Dish) [1] => stdClass Object ([menutype] => A [groupx] => 1 [titleng] => Soup Porrdg) [2] => stdClass Object ([menutype] => A [groupx] => 2 [titleng] => Hot food [titlech] => Hot food) [3] => stdClass Object ([menutype] => A [groupx] => 3 [titleng] => vegetarian dishes [titlech] => Veget-able) [4] => stdClass Object ([menutype] => A [groupx] => 4 [titleng] => staple Food [titlech] => Main Food) [5] => stdClass Object ([menutype] => A [groupx] => 5 [titleng] => grilled fish beer fish [titlech] => grilled fish beer fish) [6] => stdClass Object ([menutype] => A [groupx] => 6 [titleng] => dry pot [titlech] => Gangou Hotpot) [7] => stdClass Object ([menutype] => A [groupx] => 7 [titleng] => titlech [titlech] => Sheet Hotpot) [8] => stdClass Object ([menutype] => A [groupx] => 8 [titleng] => casserole [titlech] => Sha Guo) [9] => stdClass Object ([menutype] => A [groupx] => 9 [titleng] => [titlech] =>) [10] => stdClass Object ([menutype] => A [groupx] => 10 [titleng] => [titlech] => Special Food) [11] => stdClass Object ([menutype] => A [groupx] => 11 [titleng] => 18 brewed [titlech] => 18 brewed) [12] => stdClass Object ([menutype] => A [groupx] => 12 [titleng] => beverage Tea [titlech] => Drink Tea) [13] => stdClass Object ([menutype] => A [groupx] => 13 [titleng] => other custom [titlech] => other custom) [14] => stdClass Object ([menutype] => A [groupx] => 14 [titleng] => liquor Beer [titlech] => Wine Beer ))

It seems like you have done it !!!
Why is the substr () parameter 3? Is it 3 if other json files are processed? Do you still need to make a decision?

The BOM header of UTF-8 is three characters. Therefore, use substr to skip the first three characters.
Since json is output, the program file must be savedUTF-8 without BOMFormat

Thank you !!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.