Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to retrieve array in php sent from iOS
    text
    copied!<p>Following is my iOS code that sends NSmutable Array to PHP webservice:</p> <pre><code> // Getting Server Address AppDelegate *appDelegate = [[UIApplication sharedApplication] delegate]; NSString *serverAddress = [appDelegate getServerAddress]; serverAddress = [serverAddress stringByAppendingString:@"ABC.php"]; NSLog(@"Server Address: %@",serverAddress); NSData *post = [NSJSONSerialization dataWithJSONObject:UsersArray options:NSJSONWritingPrettyPrinted error:nil]; NSString *postLength = [NSString stringWithFormat:@"%d", [post length]]; NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:[NSURL URLWithString:serverAddress]]; [request setHTTPMethod:@"POST"]; [request setValue:postLength forHTTPHeaderField:@"Content-Length"]; [request setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"]; [request setHTTPBody:post]; [request setCachePolicy:NSURLRequestReloadIgnoringLocalCacheData]; [request setTimeoutInterval:30]; NSOperationQueue *queue = [[NSOperationQueue alloc] init]; [NSURLConnection sendAsynchronousRequest:request queue:queue completionHandler:^(NSURLResponse* theResponse, NSData* theData, NSError* error){ //Do whatever with return data NSString *result = [[NSString alloc] initWithData:theData encoding:NSUTF8StringEncoding]; NSLog(@"Result : %@",result); }]; </code></pre> <p>I want to retrive that array in PHP. How can I do that?</p> <p>Here is the php which I tried but returns null:</p> <pre><code>$handle = fopen('php://input','r'); $jsonInput = fgets($handle); // Decoding JSON into an Array $decoded = json_decode($jsonInput,true); echo json_encode($decoded); </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload