When I create an ios interface, the other side sends multiple json strings. how can I match the json data with the database data?

Source: Internet
Author: User
When I create an ios interface, the other side sends multiple json strings. how can I match the json data with the database data? When I create an ios interface, the other side sends multiple json strings. how can I match the json data with the database data?

My idea is to first judge the number of json strings based on the json Array sent from ios, and then perform loop matching. I wonder if the method is correct.

How can I determine how many json strings are in a json Array?


Reply to discussion (solution)

First, let's look at the data.

?? What is the format? ?

After json_decode is normal ???? Yes ??? .

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

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



Click the json string json_decoe () to obtain the array format.

If the key names of incoming data are the same

$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')

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.