从Web服务解析数据时发生错误

时间:2012-11-02 21:30:00

标签: iphone ios xcode json

使用JSON Parser解析此处时发生错误 见下面的代码

- (void)loadDataSource  {  
    // Request  
    NSString *URLPath = [NSString   stringWithFormat:@"https://ajax.googleapis.com/ajax/services/feed/find?   v=1.0&q=Official%20Google%20Blogs"];      
    NSURL *URL = [NSURL URLWithString:URLPath];  
    NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:URL];

    [NSURLConnection sendAsynchronousRequest:request queue:[NSOperationQueue mainQueue] completionHandler:^(NSURLResponse *response, NSData *data, NSError *error) {

        NSInteger responseCode = [(NSHTTPURLResponse *)response statusCode];

        if (!error && responseCode == 200) {
            id res = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error:nil];
            if (res && [res isKindOfClass:[NSDictionary class]]) {
                self.items = [res objectForKey:@"gallery"];
                [self dataSourceDidLoad];
            } else {
                [self dataSourceDidError];
            }
        } else {
            [self dataSourceDidError];
        }
    }];
}

我把断点,从NSURL Connection.consider跳过,如果上述代码有任何错误

提前致谢

1 个答案:

答案 0 :(得分:0)

您的网址中有空白区域。确保网址正确无误。