PHP API interface Required output JSON format data instance detailed

Source: Internet
Author: User
Tags php json
This article mainly introduces you to the PHP API interface necessary output JSON format data related to the text in the sample code introduced in very detailed, for everyone has a certain reference learning value, the need for friends below to see together.

Objective

We have to write the interface in the daily development work, the output of JSON-formatted text is the production interface must be mastered, now the interface is basically in JSON format data. The following words do not say, to see the details of this article:

Simple php json file output:

<?php$data =array (' request ' = ' success ', ' msg ' = ' 35235 '); $data _json = Json_encode ($data); header (' Content-type:text/json '); echo $data _json;? >

In this way, we can get a page in the form of JSON format, which can be modified using the reference.

How to read an interface JSON file:

<?php$data =file_get_contents (' Http://api.1yhaha.cn/v1/sms/send-validate-code '); $data _new = Json_decode ($data) ; Var_dump ($data _new);? >

Obviously, the interface address is: Http://api.1yhaha.cn/v1/sms/send-validate-code, I was through http://api.1yhaha.cn/v1/sms/ Send-validate-code this address to read the information, read out the data is in JSON format, need to decode, the resulting $data_new will be a data object, how to use the data you will know the print.

Related recommendations:

How to use Ajax to receive JSON data in thinkphp, thinkphpjson_php tutorial

PHP JSON operation, Phpjson operation _php Tutorial

Thinkphp two implementations of JSON return via Ajax, thinkphpjson_php tutorial

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.