PHP array to iOS NSArray -


okay, have array in php. 1 want in obj-c $jsonfiltereduniquecolumns. know can convert json , parse obj-c, whenever that, null value.

php:

//let's create variables         $username = $_get['username'];          //let's userid         $useridquery = sprintf("select id user_info username = '$username';");         $useridresult = mysqli_query($connect, $useridquery);         $userid_row = mysqli_fetch_array($useridresult);         $id = $userid_row['id'];          //let's search tables user's existence         $existencetablesquery = sprintf("select distinct table_name information_schema.columns column_name in ('$username') , table_schema='u830212761_users';");         $existencetablesresult = mysqli_query($connect, $existencetablesquery);          if ($existencetablesresult === false) {             die(mysqli_error($connect));         }          $tables = array();         while ($existencetablesrow = mysqli_fetch_assoc($existencetablesresult)) {             array_push($tables, $existencetablesrow['table_name']);         }          //let's other person name          $tablescount = count($tables);         $emptycolumn = array();         $messages = array();         ($i = 0; $i < $tablescount; $i++) {              $searchquery = sprintf("select * `%s`;",$tables[$i]);             $searchresult = mysqli_query($connect, $searchquery);              if ($searchresult === false) {                 die(mysqli_error($connect));             }              while ($searchrow = mysqli_fetch_assoc($searchresult)) {                 foreach($searchrow $key => $val) {                     if (empty($val) || is_null($val)) {                         array_push($emptycolumn, $key);                     }                 }                 $messages[] = array($searchrow['sender'], $searchrow['message']);             }         }          //let's other users         $filteredcolumns = array_diff($emptycolumn, array($username));         $filtereduniquecolumns = array_unique($filteredcolumns);         $jsonfiltereduniquecolumns = json_encode($filtereduniquecolumns);         return $jsonfiltereduniquecolumns; 

and, obj-c:

//get url nsstring *urlstring = [nsstring stringwithformat:@"http://www.ezgamexchange.tk/inbox.php?username=%@",user]; nsurl *url = [nsurl urlwithstring:urlstring];  //create request nsmutableurlrequest *request = [[nsmutableurlrequest alloc]init]; [request seturl:url]; [request sethttpmethod:@"get"];  nsdata *data = [nsurlconnection sendsynchronousrequest:request returningresponse:nil error:nil]; nserror *error; nsdictionary *json = [nsjsonserialization jsonobjectwithdata:data options:kniloptions error:&error]; int jsoncount = [json count]; nslog(@"%i",jsoncount); 

did check returned value php script?

if array, should store within nsarray (or nsmutablearray).

by way, nsdictionary or nsarray, did alloc/init object?

nsdictionary *json = [[nsdictionary alloc] init]; json = [nsjsonserialization jsonobjectwithdata:data options:kniloptions error:&error]; 

or:

nsarray *json = [[nsarray alloc] init]; ... 

Comments

Popular posts from this blog

database - VFP Grid + SQL server 2008 - grid not showing correctly -

jquery - Set jPicker field to empty value -

.htaccess - htaccess convert request to clean url and add slash at the end of the url -