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