PHP Read parse JSON file

Source: Internet
Author: User
 
 
  ";  $json 2_string= ' {"  tsnpm": {    "name": "#特色牛排面 #", "Score": "(4.7 points)", "Price": "¥9.0", "description": "Full of rivalry, 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 ":" Fragrant and 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, inexpensive!" "  }}'; $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?


Reply to discussion (solution)

Is your JSON file a UTF-8 format with a BOM header? Remove BOM head look down

Which one is $json2_string, put it separately.

./js/recommendmenu.json open it up with a connection, okay?

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?

$obj =json_decode ($json 2_string,true);
if (!is_array ($obj)) Die (' no successful ');

A hint?

Is your JSON file a UTF-8 format with a BOM header? Remove BOM head look down


The first floor is right, my code is the utf-8 format of the BOM header, minus the same as the string

./js/recommendmenu.json open it up with a connection, okay?


Yes, on line 39th.

Is the first floor of the problem that I use the wrong code, thank you for your enthusiastic reply

  • 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.