Following is my iOS code that sends NSmutable Array to PHP webservice:
// 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);
}];
I want to retrive that array in PHP. How can I do that?
Here is the php which I tried but returns null:
$handle = fopen('php://input','r');
$jsonInput = fgets($handle);
// Decoding JSON into an Array
$decoded = json_decode($jsonInput,true);
echo json_encode($decoded);