如何解决如何处理json输出中的responseString并对其进行解析
|| 我正在使用以下代码,并且在JSON中获取响应字符串。我不知道如何解析它。如果要在JSON输出上调用任何方法,下一步该怎么办 // 源代码- (void)viewDidLoad
{
[super viewDidLoad];
dataWebService = [[NSMutableData data] retain];
NSMutableURLRequest *request = [[NSMutableURLRequest requestWithURL:[NSURL URLWithString:@\"https://www.googleapis.com/customsearch/v1?key=AIzaSyDzl0Ozijg2C47iYfKgBWWkAbZE_wCJ-2U&cx=017576662512468239146:omuauf_lfve&q=lectures&callback=handleResponse\"]]retain];
NSURLConnection *myConnection = [NSURLConnection connectionWithRequest:request delegate:self];
[myConnection start];
}
- (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response
{
[dataWebService setLength:0];
}
- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data
{
[dataWebService appendData:data];
}
- (void)connectionDidFinishLoading:(NSURLConnection *)connection
{
NSString *responseString = [[NSString alloc] initWithData:dataWebService encoding:NSUTF8StringEncoding];
NSLog(@\"Response: %@\",responseString);
[responseString release];
[dataWebService release];
}
- (void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error
{
NSLog(@\"Error during connection: %@\",[error description]);
}
解决方法
使用JSON解析框架:http://code.google.com/p/json-framework/
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。