-JSONValue失败错误跟踪

时间:2011-12-19 23:34:23

标签: objective-c json cocoa json-framework

如何解决这个问题

  

-JSONValue失败。错误跟踪是:(       "错误域= org.brautaset.JSON.ErrorDomain代码= 11 \"字符串的意外结束\" UserInfo = 0x6173d50 {NSLocalizedDescription =字符串意外结束}"

这是我的代码

- (void)connectionDidFinishLoading:(NSURLConnection *)connection {
    NSString *str = [[[NSString alloc] initWithData:buffer encoding:NSUTF8StringEncoding] autorelease];

    NSArray *array = [str JSONValue];

    if (!array)
        return;

    NSDateFormatter *fmt = [[[NSDateFormatter alloc] init] autorelease];
    [fmt setDateFormat:@"yyyy-MM-dd"];

    for (NSDictionary *dict in array) {
        NSLog(@"Class of eve_date = %@", [[dict objectForKey:@"eve_date"]class]);

        NSDate *d = [fmt dateFromString:[dict objectForKey:@"eve_date"]];

        NSLog(@"%@",d);
        [eventPHP addObject:[Events eventsNamed:[dict objectForKey:@"title_event"] description:[dict objectForKey:@"description"] date:d]];
    }
}

这是从服务器检索的数据:

{"event":[{"eve_date":"2011-12-24","eve_time":"1 pm","title":"Tooth Regeneration Research","decription":"Tooth Regeneration Research:Where Do we stand today?\r\n\r\nBy: Dr.Tarek H El-Bialy,phD,FRCD(c)\r\n\r\nvenue:VIP ROOM,college of Dentistry,KSU"},{"eve_date":"2011-12-21","eve_time":"8 am","title":"The First Knowledge Translation(KT)","decription":"The First Knowledge Translation(KT)symposium in saudi Arabia\r\n\r\nvenue: main Auditorium,college of medicine\r\n\r\nFor Registration and further inquiries please concat:\r\n\r\nTel:4690790\/Email:ebhc-kt@ksu.edu.sa"}]}

1 个答案:

答案 0 :(得分:0)

错误表示您要求反序列化的JSON blob不完整。换句话说,你没有把它形成一个格式良好的JSON。要么从服务器返回不完整的数据,要么在进入时没有正确存储它。