What is the JSON requirement for ios-php to the app?

Source: Internet
Author: User
I get the data out of the database and send it to the web, so the app gets the information:

$result = mysql_query("select * from his");while ($arr = mysql_fetch_assoc($result)) {    $json = json_encode($arr,JSON_UNESCAPED_UNICODE);    echo $json;}

The JSON output to the interface is:
{"hps_userid":"1","hps_userid2":"1"}
Is it my output format problem or the app side problem that the app can't get data now?

Now the app's colleague says it needs this format to

{"No.":[{"hps_userid":"1","hps_userid2":"1"}]}

When searching for multiple data, how do I output it?

Reply content:

I get the data out of the database and send it to the web, so the app gets the information:

$result = mysql_query("select * from his");while ($arr = mysql_fetch_assoc($result)) {    $json = json_encode($arr,JSON_UNESCAPED_UNICODE);    echo $json;}

The JSON output to the interface is:
{"hps_userid":"1","hps_userid2":"1"}
Is it my output format problem or the app side problem that the app can't get data now?

Now the app's colleague says it needs this format to

{"No.":[{"hps_userid":"1","hps_userid2":"1"}]}

When searching for multiple data, how do I output it?

"Now the app side colleagues say that need this format can", "just can", haha ...
I've heard a similar story before when I worked with someone else, but then I learned about Android development ...
Mom eggs, only to find, obviously they parse JSON code not how can write, also blame I give the format is wrong ...

As long as the output is the standard JSON format, the information is complete, the organization is correct, there is no resolution of the problem.

{"No.":[{"hps_userid":"1","hps_userid2":"1"}]}

The existence of this "no" is not necessary (just because they are not very good at JSON parsing).
In other words, "when searching for multiple data, how do you output it?" "
This kind of problem should be considered right from the start, okay?

[    {        "hps_userid": "1",        "hps_userid2": "1"    },    {        "hps_userid": "2",        "hps_userid2": "3"    },    {        "hps_userid": "4",        "hps_userid2": "5"    }]

Take more than one piece of data, save it in an array, and then turn the array into JSON, that's it.
How can you say your code is like this ...

$result = mysql_query("select * from his");while ($arr = mysql_fetch_assoc($result)) {    $json = json_encode($arr,JSON_UNESCAPED_UNICODE);    echo $json;}

Do you know how many times the while loop? Each time the loop echoes, the final output is something like this:

{"hps_userid":"1","hps_userid2":"1"}{"hps_userid":"1","hps_userid2":"1"}{"hps_userid":"1","hps_userid2":"1"}{"hps_userid":"1","hps_userid2":"1"}{"hps_userid":"1","hps_userid2":"1"}{"hps_userid":"1","hps_userid2":"1"}

This kind of connection is not a JSON string at all ...
。。。。。。
As follows:

$result = mysql_query("select * from his");$Temp = array();$row = mysql_fetch_assoc($result);while ($row) {    $Temp[] = array("hps_userid"=>$row["hps_userid"],"hps_userid2"=>$row["hps_userid2"]);    $row = mysql_fetch_assoc($result);}die(json_encode($Temp));//或者你就听你们那个逗比APP工程师的://die(json_encode(array("No."=>$Temp)));

Here is the need to loop, so you're going to tease the JSON for you than the engineer, which is needed in [{xxx:1},{xxx:2}] this format

  • 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.