dimanche 30 novembre 2014

My JSONObjectWithData is null

I have a problem with my JSON who send me a null value.


I think it's not a problem with my webservice in PhP because my colleague who is a expert in PhP doesn't see any error


Just below my Obj-C code



dispatch_queue_t downloadQueue = dispatch_queue_create("downloader", NULL);

dispatch_async(downloadQueue, ^{
NSData *result = self.envoyerLaDemande;
dispatch_async(dispatch_get_main_queue(), ^{

id strResult=nil;

strResult = [NSJSONSerialization JSONObjectWithData:result options:0 error:nil];

NSLog(@"strResult: %@", strResult);

NSString* boolOk=[strResult objectForKey:@"result"];
NSLog(@"BoolOk: %@", boolOk);


And there is the PHP script



$data = array();

if(condition == 1)
{
$data["result"] = "ok";
}
else
{
$data["result"] = "error";
}
$data["result"] = "coucou";
}
echo json_encode($data);


And the methode envoyerLaDemande



-(NSData*)envoyerLaDemande{


NSURL *url = [NSURL URLWithString:@"http://mywebsite.com.com/App/V2/mailTo.php"];
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url];

NSString* requestFields;


requestFields = [NSString stringWithFormat:@"agence=%@&", nomAgence];

request.HTTPBody = requestData;
request.HTTPMethod = @"POST";

NSHTTPURLResponse *response = nil;
NSError *error = nil;
NSData *responseData = [NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&error];
if (error == nil && response.statusCode == 200) {
} else {
}
return responseData;

}



Aucun commentaire:

Enregistrer un commentaire