CI notes, using JSON

Source: Internet
Author: User

    1. The processing transformation of JSON,
    2. JSON conversion steps,

A) Set the JSON to an empty string first,

b) While loop, Traverse, while (!! $row = Mysql_fetch_array ($query, MYSQL_ASSOC))

c) splicing json, $json. = Json_encode ($row). ', ';

D) minus the last comma, $json = substr ($json, 0,-1);

e) Echo,json. can.

    1. Guess, in CI, the echo of the controller can be implemented without the view of the JSON call. Pending Code Validation
    2. One of the previous JSON combinations of the construction process, the testability code for

First, Print_r prints the array,

View the page source code,

For the first time, the point equals Jsonencode after the code is

Each one is an object, but each end has no comma, it needs a comma, and then constructs the $json, the previous step, $json. = Json_encode ($row);

After that, this step is, $json. = Json_encode ($row). “,”;

One more comma,

Final treatment,

$json = substr ($json, 0,-1);

Finally, the JSON of the array structure needs to be preceded by the [] symbol

The subsequent call, which can be used in the URL,

CI notes, using JSON

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.