错误将NSdata存储到NsDictionary

时间:2015-02-05 11:28:18

标签: ios nsdictionary nsdata

plz帮我解析JSON数据。我们在NSMutable Data中获得响应。但是我们不会在Dictionary中取出数据。我的jsonDictionary得到零。 这是我的网址。我检查了JSON Validator。它们显示了有效的Json输出。帮助....

http://mobileapp.merucabs.com/NearByCab_ETA/GetNearByCabs.svc/rest/nearby?Lat=23.0768222&Lng=72.645732&SuggestedRadiusMeters=5000&CabMaxCount=10

-(void)connectionDidFinishLoading:(NSURLConnection *)connection {

   // NSString *responseString = [[NSString alloc] initWithData:receivedData encoding:NSUTF8StringEncoding];
    //NSLog(@"Response String is %@",responseString);
    [UIApplication sharedApplication].networkActivityIndicatorVisible = NO;


jsonDictionary=[NSJSONSerialization JSONObjectWithData:receivedData options:NSJSONReadingMutableContainers error:nil];
jsonArr=[jsonDictionary objectForKey:@"results"];
  //  NSLog(@"JSONDictionary is %@",jsonDictionary);
[_categoryListTableView reloadData];


}

3 个答案:

答案 0 :(得分:0)

enter image description here您的json服务返回无效的json。如果你检查那个网址的源代码,你会发现

<string xmlns="http://schemas.microsoft.com/2003/10/Serialization/">

在文件的标题上。使用jsonlint.com等一些验证工具确保json有效性

答案 1 :(得分:0)

我从URL获得了输出,我创建了新项目并运行,项目链接是附加here

答案 2 :(得分:0)

从结果<stringxmlns="http://schemas.microsoft.com/2003/10/Serialization/">中删除该行 然后再试一次

-(void)connectionDidFinishLoading:(NSURLConnection *)connection {

id jsonDictionary=[NSJSONSerialization JSONObjectWithData:receivedData options:kNilOptions error:nil];
    NSLog(@"JSONDictionary is %@", jsonDictionary);
}