A small hole in PHP that can't output json_encode

Source: Internet
Author: User

Obviously the old code, how to change a place will not be executed. The first suspect is the PHP version.

Finally know is my editor nodepad++ to the pit. Maybe it's not nodepad++ 's pit. In short, you need to convert to utf-8 format encoding to

<?PHPHeader(' access-control-allow-origin:* '); Header(' Access-control-allow-methods:get,post '); Header(' Access-control-allow-headers:x-requested-with,content-type '); classMenu {//The menu ID, which is taken from the database     Public $id= 0; //Menu Name     Public $name= ' '; //Connection Address     Public $link= ' '; //icons     Public $icon= ' '; //submenu, which is a list, must be initialized to an empty array, otherwise the front end will be faulted     Public $subMenu= []; //constructor Function     Public function__construct ($id,$n,$l,$icon= ' ') {        $this->id =$id; $this->name =$n; $this->link =$l; $this->icon =$icon; }}//Menu Items$userMang=NewMenu (' 1000 ', ' User management ', ' ', ' users ');$USERADD=NewMenu (' 1001 ', ' User new ', '/user/add ');$userList=NewMenu (' 1002 ', ' user list ', '/user/list '));$userMang->submenu = [$USERADD,$userList];//management of the station inner letter$msgMang=NewMenu (' 1010 ', ' Station letter management ', ' ', ' laptop '));$MSGADD=NewMenu (' 1011 ', ' post-site letter ', '/msg/add '));$msgList=NewMenu (' 1012 ', ' Station letter list ', '/msg/list '));$msgMang->submenu = [$MSGADD,$msgList];Header(' Content-type:application/json ');Exit(Json_encode ([$userMang,$msgMang]));

A small hole in PHP that can't output json_encode

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.