Je rencontre des problèmes lors de l'analyse des données envoyées à un service Web php. J'utilise le code suivant pour obtenir le JSON:json_decode renvoie une valeur nulle à partir de l'application iOS
$decoded = json_decode(file_get_contents('php://input'));
if(is_null($decoded) == NULL)
{
$body = "Data was not successfully received";
$body = $body . " " . $jsonInput;
}
Le JSON est envoyé à partir d'une application iOS et ressemble à ce qui suit:
{
"water" : "YES",
"int_clean" : "YES",
"ceiling_stains" : "YES",
"additional_comments" : "not entered",
"roof_cond" : "YES",
"e_clean" : "YES",
"interior_cond" : "not entered",
"no_exp" : "not entered",
"addr" : "YES",
"roof_leak" : "YES",
"doors_sec" : "YES",
"elec" : "YES",
"ceiling_exp" : "not entered",
"repaired" : "YES",
"o_desc" : "not entered",
"w_sign" : "YES",
"o_cond" : "not entered",
"int_cond" : "YES",
"gas" : "YES",
"for_sale_sign" : "YES",
"sold_as_is" : "YES",
"mb_sign" : "YES",
"graffiti" : "YES",
"date" : "18-12-2012 18:58",
"dewinterized" : "YES",
"HVAC" : "YES",
"why_no_mat" : "not entered",
"is_lockbox" : "YES",
"financing_mat" : "YES",
"yard_cond" : "YES",
"marketing_mat" : "YES",
"HVAC_missing" : "not entered",
"agent_info" : "YES",
"e_cond" : "YES",
"e_key" : "YES",
"pool_sec" : "YES",
"pool_clean" : "YES"
}
et de l'envoyer avec ce code:
NSDictionary * info = [NSDictionary dictionaryWithObjects:values forKeys:keys];
NSData* jsonData = [NSJSONSerialization dataWithJSONObject:info options:NSJSONWritingPrettyPrinted error:&error];
NSMutableURLRequest *req = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:@"http://uofi-bars.com/sendEmail.php"]];
[req addValue:@"Content-Type: application/json" forHTTPHeaderField: @"Content-Type"];
[req setHTTPMethod:@"POST"];
[req setHTTPBody:jsonData];
[NSURLConnection sendSynchronousRequest:req returningResponse:&response error:&error];
Je suis complètement nouveau pour php et cela me donne mal à la tête depuis un certain temps. Toute aide serait appréciée!
'if (is_null ($ décodé) == NULL)'? pourquoi pas 'if (is_null ($ decoded))' – Musa
bingo, merci haha – thebiglebowski11