0

如何解决这个异常

-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"}]}
4

1 回答 1

0

该错误意味着您要求它反序列化的 JSON blob 不完整。换句话说,你没有给它一个格式良好的 JSON blob。要么你从服务器得到不完整的数据,要么你没有在它进来时正确存储它。

于 2011-12-20T00:17:49.250 回答