-JSONValue failed Error trace

2.7k Views Asked by At

how solve this excepetion

-JSONValue failed. Error trace is: ( "Error Domain=org.brautaset.JSON.ErrorDomain Code=11 \"Unexpected end of string\" UserInfo=0x6173d50 {NSLocalizedDescription=Unexpected end of string}"

this is my code

- (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]];
    }
}

This is the data retrieve from server :

{"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:[email protected]"}]}
1

There are 1 best solutions below

4
Lily Ballard On

The error means the JSON blob you asked it to deserialize is incomplete. In other words, you didn't hand it a well-formed blob of JSON. Either you got incomplete data back from the server, or you didn't store it properly as it came in.