我想更新我在应用中离线编译的json
中的ios app
文件。刷新应用程序时,应从服务器更新文件:localhost:8888/ios/ios_app/Service/data.json
请帮忙...... 提前谢谢
答案 0 :(得分:0)
当我需要获取可以序列化为字符串类型的值时,我使用SOAP。但如果您需要的只是json
文件,请查看NSURLConnection
类。
- (void)downloadJSONFromURL {
NSURLRequest *request = ....
NSURLConnection *urlConnection = [[NSURLConnection alloc] initWithRequest:urlRequest delegate:self];
// ...
}
NSData *urlData;
- (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response {
urlData = [[NSMutableData alloc] init];
}
- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data {
[urlData appendData:data];
}
- (void)connectionDidFinishLoading:(NSURLConnection *)connection {
NSError *jsonParsingError = nil;
id object = [NSJSONSerialization JSONObjectWithData:urlData options:0 error:&jsonParsingError];
if (jsonParsingError) {
DLog(@"JSON ERROR: %@", [jsonParsingError localizedDescription]);
} else {
DLog(@"OBJECT: %@", [object class]);
}
}