1

私はiPhoneプログラミングが初めてです。

そのアレイをサーバーのファイルに追加し、サーバーのファイルを更新しNSMutableArrayたいものがあります。POSTphpxml

前もって感謝します。

4

1 に答える 1

1

このコードが必要な場合があります。

NSURLConnection * postConnectionの参照を.hで宣言し、それをプロパティにして.mファイルで合成します。

NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:[NSURL URLWithString:@"yourPhpUrl.php"]];

[request setHTTPMethod:@"POST"];

NSMutableDictionary *jsonDict = [[NSMutableDictionary alloc] init];
[jsonDict setValue:yourArray forKey:@"userName"];
NSLog(@"JSON Dict: %@",jsonDict);//Check your array here...


NSData *jsonData = [NSJSONSerialization dataWithJSONObject:jsonDict options:kNilOptions error:nil];
NSString *jsonString = [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding];
NSLog(@"JSON String: %@",jsonString); //Check your post String here...

[request setValue:@"application/json" forHTTPHeaderField:@"Accept"];
[request setValue:@"application/json" forHTTPHeaderField:@"Content-Type"];

[request setValue:@"json" forHTTPHeaderField:@"Data-Type"];
[request setValue:[NSString stringWithFormat:@"%d", [jsonData length]] forHTTPHeaderField:@"Content-Length"];
[request setHTTPBody: jsonData];

self.postConnection = [[NSURLConnection alloc] initWithRequest:request delegate:self startImmediately:true];

これがあなたを助けるかもしれません

于 2012-07-02T11:34:48.523 に答える