Interface for returning JSON data

Source: Internet
Author: User
To return JSON data, you need to write an interface that only gives a connection and returns JSON data. how can this interface be implemented?


Reply to discussion (solution)

Is the connection output json? What does that mean?

$ Arr = array ('connection successfully'); echo json_encode ($ arr );

This is the simplest thing.

Is the connection output json? What does that mean?

About It
It is to return different data for a connection by concatenating different parameters.

If.

Http: // sxxxxx/json. php? Type = 1
Http: // sxxxxx/json. php? Type = 2

header('Content-type: application/json');$type = isset($_GET['type']) ? intval($_GET['type']) : 1;$array = array();if ($type == 1) {  $array = array("test" => "I'm 1");} else if ($type == 2) {  $array = array("test" => "I'm 2");}echo json_encode($array);

Http: // sxxxxx/json. php? Type = 1
Http: // sxxxxx/json. php? Type = 2

header('Content-type: application/json');$type = isset($_GET['type']) ? intval($_GET['type']) : 1;$array = array();if ($type == 1) {  $array = array("test" => "I'm 1");} else if ($type == 2) {  $array = array("test" => "I'm 2");}echo json_encode($array);

++

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.