【发布时间】:2013-11-30 21:45:01
【问题描述】:
我现在找不到有用的示例。我的服务器上有一个 php 脚本,它从选定的数据库表中返回所有数据。我正在尝试从我的客户端 ios 设备中获取它并解析该 json,以便我可以查看那里的内容并将其中一些数据添加到我的 sqlite 数据库中。我现在正在使用 fmdb 作为包装器。这是我连接到服务器的代码,我不确定从那里去哪里
NSURL *url = [NSURL URLWithString:@"http://index.php"];
NSString * post =[NSString stringWithFormat:@"lang=%@",@"English"];
NSData *postData = [post dataUsingEncoding:NSUTF8StringEncoding allowLossyConversion:YES];
NSString *postLength = [NSString stringWithFormat:@"%d", [postData length]];
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init];
[request setTimeoutInterval:60];
[request setURL:url];
[request setHTTPMethod:@"POST"];
[request setValue:postLength forHTTPHeaderField:@"Content-Length"];
[request setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"];
[request setHTTPBody:postData];
NSURLConnection* connection = [[NSURLConnection alloc] initWithRequest:request delegate:self];
[connection start];
我的json数据是这样的
{"login":[{"userid":"1","password":"test","aclevel":"1"}],"answers":[{"aid":"1","qid":"1","sid":"1","freetext":null,"a":null,"b":null,"c":null,"d":null,"e":null,"f":null,"g":null,"h":null,"i":null,"j":null,"synch":null,"type":null},{"aid":"5","qid":"5","sid":"5","freetext":null,"a":null,"b":null,"c":null,"d":null,"e":null,"f":null,"g":null,"h":null,"i":null,"j":null,"synch":null,"type":null}],"projects":{"pid":"3","name":"apmatt","descr":"tapest","creator":"macurlatt","datetime":null,"synch":null},"questions":[{"qid":"1","pid":"1","sid":"1","question":null,"a":null,"b":null,"c":null,"d":null,"e":null,"f":null,"g":null,"h":null,"i":null,"j":null,"synch":null,"type":null}],"surveys":[{"sid":"2","pid":"2","name":"matt","descr":"test","creator":"matt","datetime":null,"synch":null},{"sid":"3","pid":"3","name":"amatt","descr":"taest","creator":"maatt","datetime":null,"synch":null}]}
【问题讨论】:
标签: php ios objective-c json sqlite