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