How do I match JSON data to database data when I'm working on an iOS interface with multiple JSON strings coming in from the other side?

Source: Internet
Author: User
How do I match JSON data to database data when I'm working on an iOS interface with multiple JSON strings coming in from the other side?

My idea is to determine how many JSON strings there are based on the JSON array that came from iOS, and then loop the match. I do not know whether the method is correct.

How do I tell how many JSON strings are in a JSON array?


Reply to discussion (solution)

Let's see what kind of data it is.

?? How is the format?

After normal json_decode???? can be solved??? The

The data format is [{"Answer": "123"},{"Answer": "222"},{"answer": "231"}]

The data format is [{"Answer": "123"},{"Answer": "222"},{"answer": "231"}]



The resulting JSON string is Json_decoe () to get the array form.

If the key names for the incoming data are the same, the

$s = ' [{"Answer": "123"},{"Answer": "222"},{"answer": "231"}] '; $d = Json_decode ($s, true); $t = Join (', ', Array_map (' Current ', $d)), $k = key (current ($d)), $sql = "SELECT * from Tbl_name where $k in ($t)";
SELECT * from Tbl_name where answer in (123,222,231)

$data = ' [{"Answer": "123"},{"Answer": "222"},{"answer": "231"}] '; $data = Json_decode ($data, true); $answers = Array (); foreach ($data as $val) {    Array_push ($answers, $val [' answer ']);} $SQLSTR = "SELECT * from table where answer in ('". Implode ("', '", $answers). "')"; #mysql_query ($sqlstr) or Die (Mysql_error ()); Echo $sqlstr; SELECT * FROM table where answer in (' 123 ', ' 222 ', ' 231 ')
  • 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.