如何通过“获取方法”从Web服务中获取数据并将其保存到iPhone中的可变字典中..... thnx
最佳答案
如果您使用的是JSOn网络服务来获取数据,请尝试使用本教程
#import
@interface jsonViewController : UIViewController {
IBOutlet UILabel *label;
NSMutableData *responseData;
}
Replace the contents of jsonViewController.m with:
#import "jsonViewController.h"
#import "JSON/JSON.h"
@implementation jsonViewController
- (void)viewDidLoad {
[super viewDidLoad];
responseData = [[NSMutableData data] retain];
NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:@"http://www.yourwebservice.com"]];
[[NSURLConnection alloc] initWithRequest:request delegate:self];
}
- (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response {
[responseData setLength:0];
}
- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data {
[responseData appendData:data];
}
- (void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error {
label.text = [NSString stringWithFormat:@"Connection failed: %@", [error description]];
}
- (void)connectionDidFinishLoading:(NSURLConnection *)connection {
[connection release];
NSString *responseString = [[NSString alloc] initWithData:responseData encoding:NSUTF8StringEncoding];
[responseData release];
NSArray *tempArray = [responseString JSONValue];
}
关于iphone - 如何通过Get方法从Web服务中获取数据并想保存到iPhone SDK中的Mutable Dictionary中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9222883/