views:

29

answers:

0

My problem is quite simple, I'm sometimes receiving a JSON connection without the whole JSON value in connection, as such I'm getting 2 fragments, together making a whole. I can't call [jsonstring JSONValue]; until I have both joined together.

The problem is, it is sometimes, so I really want to know in advance whether JSONValue will work. Placing it in the try catch clause fails because the application is crashed before it can catch it.

See below:

- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data 
{   
    @try 
    {

NSLog(@"ServerAccessor2::connection:reply");

//[NSThread sleepForTimeInterval:1];

jsonString = [[[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding] autorelease];// Store incoming data into a string

NSLog(@"%@", jsonString);   

    if(jsonString == nil)
    {
        jsonString = [[NSMutableString alloc] initWithData:data encoding:NSUTF8StringEncoding];

    }
    else {
        NSMutableString *temp_string = [[NSMutableString alloc] initWithString:jsonString];

        [jsonString release];
        jsonString = [[NSMutableString alloc] initWithData:data encoding:NSUTF8StringEncoding];
        [temp_string appendString:jsonString];

        [jsonString release];
        jsonString = [[NSMutableString alloc] initWithString: temp_string];
        [temp_string release];

    }
}

At which point I want to parse the jsonstring...