JSON-encapsulated communication interface in the app interface

Source: Internet
Author: User

1 classes that encapsulate JSON communication interfaces2<?PHP3      classresponse{4         /**5 * Output communication data in JSON mode6 * @param integer $code status code7 * @param string $message tip information8 * @param array $data data9 * Return stringTen          **/ One           Public Static functionJson$code,$message="",$data=Array()){ A             if(!Is_numeric($code)) { -                 return""; -             } the              $result=Array( -' Code ' =$code, -' Message ' =$message, -' Data ' =$data, +              ); -             EchoJson_encode ($result); +             Exit; A          } at}
A simple way to implement a calling interface
1 <? PHP 2 require_once (' 6.php '3 $arr Array (4 ' id ' =>1,5 ' name ' = ' Zhangsan ',6 ); 7 Response::json (200, ' data return success ',$arr); 8 ?>

JSON-encapsulated communication interface in the app interface

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.