2
PHP 웹 서비스로 전송 된 데이터를 구문 분석하는 데 문제가 있습니다. 나는 JSON 얻기 위해 다음 코드를 사용하고 있습니다 : json으로는 아이폰 OS 응용 프로그램에서 전송 및처럼 보이는json_decode가 iOS 응용 프로그램에서 null 값을 반환합니다.
$decoded = json_decode(file_get_contents('php://input'));
if(is_null($decoded) == NULL)
{
$body = "Data was not successfully received";
$body = $body . " " . $jsonInput;
}
을 다음
{
"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"
}
을 그리고이 코드를 보내기 :
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];
저는 PHP에 완전히 익숙하지 않아 꽤 오랫동안 두통을 겪고 있습니다. 어떤 도움을 주시면 감사하겠습니다!
'if (is_null ($ decoded) == NULL)'? 왜 안돼? (if_null ($ decoded)) – Musa
빙고, 고마워. – thebiglebowski11