I’m getting a json from server.
I can parse only one JSON at time. But when I am getting 2 json (or more) simultaneously my parse didn’t work. It couldn’t do deserialization correctly. How do I solve this problem?
update:
I’am sending, for example, 5 requests with time interval = 0.1; Sometimes I get
{"status": "success", "msg": "Dish1 flagged"}
– it’s ok. But sometimes I get
{"status": "success", "msg": "Dish1 flagged"}{"status": "success", "msg": "Dish2 flagged"}
– it’s bad, my parser doesn’t work. If I received
{"status": "success", "msg": "Dish1 flagged"}{"status": "success", "msg": "Dish2 flagged"}
I want first json move to trash and second JSON begin to parsing.
JSON structure may be much more complex than these ones. I can control the server and it sends valid JSON.
my network class is
-(id) init
{
if(self=[super init])
{
receivedData = [[NSMutableData alloc] init];
}
return self;
}
- (void)connectionDidFinishLoading:(NSURLConnection *)connection
{
[conn release];
conn = nil;
NSError *error;
NSDictionary *dictionary = [[CJSONDeserializer deserializer] deserializeAsDictionary:receivedData error:&error];
}
- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data
{
[receivedData appendData:data];
}
- (void) createConnectionWithRequest:(NSMutableURLRequest *)request delegate:(id)delegate
{
[receivedData setLength:0];
conn = [[NSURLConnection alloc] initWithRequest:request delegate:delegate startImmediately:YES];
}
How is the JSON delivered? do you have control over the formatting?
If your multiple objects are structured as an array
[{"like":"this"},{"or":"similar"}]you’ll probably have to change tobut I haven’t used that particular parser, so the syntax might not be right