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?