我也在为我的一个项目在服务器(googleappengine)上使用Python。我有一个端点,它以JSON格式返回一堆数据。(parseJSON是我自己的方法)@interface GSData : NSObject {
NSMutableData *responseData;
}
/
// in my .m file
- (void)getData {
responseData = [[NSMutableData data] retain];
NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:DATA_URL]];
[[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 {
NSLog(@"Connection failed: %@", [error description]);
}
- (void)connectionDidFinishLoading:(NSURLConnection *)connection {
[connection release];
NSString *responseString = [[NSString alloc] initWithData:responseData encoding:NSUTF8StringEncoding];
[responseData release];
[self parseJSON:responseString];
[responseString release];
}
对于JSON,我使用this project。在
希望这有帮助!在