我正在開發一個使用JSON框架的iPhone應用程序,我正在調用一個PHP腳本來更新本地服務器上的MySQL數據庫。使用這些代碼:如何從iPhone發佈請求獲取json數據
NSString *jsonString = [sendData JSONRepresentation];
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init];
NSString*post = [NSString stringWithFormat:@"&json=%@", jsonString];
NSData*postData = [post dataUsingEncoding:NSASCIIStringEncoding allowLossyConversion:NO];
[request setURL:[NSURL URLWithString:@"http://localhost:8888/update.php"]];
[request setHTTPMethod:@"POST"];
[request setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"content-type"];
[request setHTTPBody:postData];
我想問:
什麼是PHP腳本要收到請求數據,我怎麼能JSON數據進行解碼,以PHP對象更新數據庫?
任何幫助,將不勝感激。
謝謝你,我確實像你說的那樣,它完美地工作。 – haisergeant 2010-09-08 02:34:11