【发布时间】:2011-03-11 15:41:09
【问题描述】:
我是 iPhone 开发的新手。以下是将 json 中的数据从 iPhone 发布到 MySQL。数据似乎是从 iPhone 发布的,但发布时出现问题。
**- (IBAction) btnPostDataPressed : (id) sender {
NSURL *objUrl = [NSURL URLWithString : @"http://localhost/test_questionnaire/update.php"] ;
NSMutableURLRequest *theRequest = [NSMutableURLRequest requestWithURL : objUrl] ;
[theRequest setHTTPMethod : @"POST"];
[theRequest setValue : @"application/json"
forHTTPHeaderField : @"Content-Type"];
[theRequest setTimeoutInterval:10];
//NSData *myData = [[NSString alloc] initWithString:@"nasir here"];
//[NSString alloc] initWithData:myData encoding:NSUTF8StringEncoding];
NSString *stringData = [[NSString alloc] initWithString:@"nasir here"];
NSDictionary *jsonDictionary = [NSDictionary dictionaryWithObject:stringData forKey:@"code"];
NSString *jsonString = [jsonDictionary JSONRepresentation];
NSString *strHttpBody = [NSString stringWithFormat:@"%@", jsonString];
[theRequest setHTTPBody:[strHttpBody dataUsingEncoding:NSUTF8StringEncoding]];
NSURLConnection *conn = [[NSURLConnection alloc] initWithRequest:theRequest delegate:self];
textView.text = @"data successfully posted!!!";
}**
另外,我已经尝试了上面注释掉的行,但仍然存在问题。
希望得到好评。谢谢。
【问题讨论】:
-
出现什么样的问题?服务器上有什么显示吗?
标签: php iphone mysql objective-c json