PHP Read parse JSON file, how to solve

Source: Internet
Author: User
PHP Read parse JSON file
 
 $filename = "./js/recommendmenu.json";
$json _string = file_get_contents ($filename);
Echo Print_r ($json _string,true); Print the contents of a file
echo "
";

$json 2_string= ' {
"TSNPM": {
"Name": "#特色牛排面 #",
"Score": "(4.7 points)",
"Price": "¥9.0",
"description": "The rivalry is full, slightly spicy and smooth." "
},
"Mnnrm": {
"Name": "#: Minnan beef Noodle #",
"Score": "(4.8 points)",
"Price": "¥8.5",
"description": "Smooth and delicious, memorable." "
},
"HXNCM": {
"Name": "#红烧牛杂面 #",
"Score": "(4.8 points)",
"Price": "¥8.0",
"description": "Fragrance seductive, five miscellaneous!" "
},
"GWCSGJF": {
"Name": "#广味叉烧盖浇饭 #",
"Score": "(4.7 points)",
"Price": "¥8.5",
"description": "Nourishing, nourishing stomach, delicious, energetic"
},
"XHSCD": {
"Name": "#西红柿炒蛋 #",
"Score": "(4.8 points)",
"Price": "¥2.0",
"description": "Pleasant taste, cheap!" "
}
}';
$obj =json_decode ($json 2_string,true);
if (!is_array ($obj)) Die (' no successful ');
Print_r ($obj);
Echo '
'. $obj [' tsnpm '] [' name '];
?>

When I parse the $json2_string string can parse the success, but I parse from the file to get the string $json_string when it is not resolved, ask the master How to solve this?
------Solution--------------------
Is your JSON file a UTF-8 format with a BOM header? Remove BOM head look down
------Solution--------------------
Which one is $json2_string, put it separately.
------Solution--------------------
./js/recommendmenu.json open it up with a connection, okay?
------Solution--------------------
Echo Print_r ($json _string,true);
Just print the string that was read to

Don't see Json_decode ($json _string) in your code, how do you know you can't parse it?
------Solution--------------------
$obj =json_decode ($json 2_string,true);
if (!is_array ($obj)) Die (' no successful ');

A hint?
  • Related Article

    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.