Php reads and parses json files
"; $ Json2_string = '{" tsnpm ": {" name ":" # Special Steak noodles # "," score ":" (4.7 points) "," price ": "¥9.0", "description": "The competition is vigorous and refreshing. "}," Mnnrm ": {" name ":" #: Minnan beef noodle # "," score ":" (4.8 points) "," price ":" ¥8.5 ", "description": "smooth and delicious, with an endless aftertaste. "}," Hxncm ": {" name ":" # braised beef noodles # "," score ":" (4.8 points) "," price ":" ¥8.0 ", "description": "It's very attractive! "}," Gwcsgjf ": {" name ":" # wide-flavor barbecued pork cover rice # "," score ":" (4.7 points) "," price ":" ¥8.5 ", "description": "nourishing, nourishing, delicious, energetic"}, "xhscd": {"name": "# tomato scrambled eggs #", "score": "(4.8 points) "," price ":" ¥2.0 "," description ":" tastes nice and inexpensive! "} '; $ Obj = json_decode ($ json2_string, true); if (! Is_array ($ obj) die ('No successful '); print_r ($ obj); echo'
'. $ Obj ['tsnpm'] ['name'];?>
When I parse the $ json2_string string, it can be successfully parsed, but I cannot parse the string $ json_string obtained from the file. how can I solve this problem?
Reply to discussion (solution)
Is your json file in UTF-8 format with BOM header? Remove the BOM header.
Which is $ json2_string? paste them separately.
./Js/recommendMenu. json can be opened in the form of a connection?
Echo print_r ($ json_string, true );
Only print the read string
I didn't see the json_decode ($ json_string) in your code. how do you know that it cannot be parsed?
$ Obj = json_decode ($ json2_string, true );
If (! Is_array ($ obj) die ('No successful ');
Are you prompted?
Is your json file in UTF-8 format with BOM header? Remove the BOM header.
The first floor is correct. my code is in the UTF-8 format of the BOM header, and the same as the string is removed.
./Js/recommendMenu. json can be opened in the form of a connection?
Some are in the 39th rows
I am using a wrong code. thank you for your enthusiastic reply.