-1

** I have some times 168416 bytes received in one single parse.

-(void)getConnector        // PESQUISA
{
    NSMutableURLRequest *getJson = [[NSMutableURLRequest alloc] initWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@", urlEntra]]];

    [getJson setHTTPMethod:@"GET"];
    [getJson addValue:@"getValues" forHTTPHeaderField:@"METHOD"];

    receivedData = [NSMutableData data];
    NSURLConnection *connection = [[NSURLConnection alloc] initWithRequest:getJson delegate:self];
}

-(void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data
{
    [receivedData appendData:data];
}

Is there any limit for how much data I can receive with JSON? Am I receiving wrong my JSON data?

When I have "some" data it works fine, but when I have a lot of data I am not able to receive because it comes in parts and JSON do not recognizes as a single data.

Here is my JSON (JSONDictionaryExtensions):

NSData *receivedData = data;

NSDictionary *dictionary = [NSDictionary dictionaryWithJSONData:data];

Here is data received with:

NSLog(@"Dados JSON:\n%@", [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding]);

Good data sample:

2013-11-21 09:10:03.916 APP[38296:70b] Dados JSON: {"nrAutenticacao1":"120360136","dtAutenticacao1":"20/12/12","nrOrdem1":"5","dsLivro1":"DIARIO","nrAutenticacao2":"080285899","dtAutenticacao2":"11/09/08","nrOrdem2":"4","dsLivro2":"DIARIO","nrAutenticacao3":"070212953","dtAutenticacao3":"30/07/07","nrOrdem3":"3","dsLivro3":"DIARIO","nrAutenticacao4":"070212970","dtAutenticacao4":"30/07/07","nrOrdem4":"2","dsLivro4":"DIARIO","nrAutenticacao5":"070212961","dtAutenticacao5":"30/07/07","nrOrdem5":"1","dsLivro5":"DIARIO","numLivros":5}

2013-11-21 09:10:03.917 APP[38296:70b] Recebidos 495 bytes de dados.

2013-11-21 09:10:03.917 APP[38296:70b] DICTIONARY: { dsLivro1 = DIARIO; dsLivro2 = DIARIO; dsLivro3 = DIARIO; dsLivro4 = DIARIO; dsLivro5 = DIARIO; dtAutenticacao1 = "20/12/12"; dtAutenticacao2 = "11/09/08"; dtAutenticacao3 = "30/07/07"; dtAutenticacao4 = "30/07/07"; dtAutenticacao5 = "30/07/07"; nrAutenticacao1 = 120360136; nrAutenticacao2 = 080285899; nrAutenticacao3 = 070212953; nrAutenticacao4 = 070212970; nrAutenticacao5 = 070212961; nrOrdem1 = 5; nrOrdem2 = 4; nrOrdem3 = 3; nrOrdem4 = 2; nrOrdem5 = 1; numLivros = 5; }

Bad data sample:

2013-11-21 09:00:22.272 APP[38296:70b] Dados JSON: {"nrAutenticacao1":"980367425","dtAutenticacao1":"25/08/98","nrOrdem1":"7","dsLivro1":"ATA DE REUNIAO DE DIRETORIA","nrAutenticacao2":"080363784","dtAutenticacao2":"18/12/08","nrOrdem2":"9","dsLivro2":"BALANCO","nrAutenticacao3":"070179557","dtAutenticacao3":"22/06/07","nrOrdem3":"8","dsLivro3":"BALANCO","nrAutenticacao4":"060260726","dtAutenticacao4":"05/10/06","nrOrdem4":"7","dsLivro4":"BALANCO","nrAutenticacao5":"050206966","dtAutenticacao5":"23/08/05","nrOrdem5":"6","dsLivro5":"BALANCO","nrAutenticacao6":"040043258","dtAutenticacao6":"11/03/04","nrOrdem6":"5","dsLivro6":"BALANCO","nrAutenticacao7":"030152879","dtAutenticacao7":"16/10/03","nrOrdem7":"4","dsLivro7":"BALANCO","nrAutenticacao8":"030152860","dtAutenticacao8":"16/10/03","nrOrdem8":"3","dsLivro8":"BALANCO","nrAutenticacao9":"030152852","dtAutenticacao9":"16/10/03","nrOrdem9":"2","dsLivro9":"BALANCO","nrAutenticacao10":"030152844","dtAutenticacao10":"16/10/03","nrOrdem10":"1","dsLivro10":"BALANCO","nrAutenticacao11":"990032957","dtAutenticacao11":"30/03/99","nrOrdem11":"3","dsLivro11":"CAIXA PAGAMENTO","nrAutenticacao12":"990032965","dtAutenticacao12":"30/03/99","nrOrdem12":"2","dsLivro12":"CAIXA PAGAMENTO","nrAutenticacao13":"980306

... (LOT OF DATA) ...

2013-11-21 09:00:22.585 APP[38296:70b] Dados JSON: /06/98","nrOrdem419":"1","dsLivro419":"DIARIO AUXILIAR ESTOQUE","numLivros":419}

2013-11-21 09:00:22.585 APP[38296:70b] Recebidos 81 bytes de dados.

2013-11-21 09:00:22.586 APP[38296:70b] Error Domain=NSCocoaErrorDomain Code=3840 "The operation couldn’t be completed. (Cocoa error 3840.)" (JSON text did not start with array or object and option to allow fragments not set.) UserInfo=0x9d610a0 {NSDebugDescription=JSON text did not start with array or object and option to allow fragments not set.}

2013-11-21 09:00:22.587 APP[38296:70b] DICTIONARY: (null)

Andrew Barber
  • 39,603
  • 20
  • 94
  • 123
AllMac
  • 31
  • 10
  • Possible duplicate of http://stackoverflow.com/questions/1262376/is-there-a-limit-on-how-much-json-can-hold – MusicLovingIndianGirl Nov 21 '13 at 12:10
  • Exactly what size is "lot of data"? Perhaps that is a new technical unit of measure? Where is the code? – zaph Nov 21 '13 at 12:10
  • 3
    In general you're limited only by the size of available heap. But your scenario is quite common when you attempt to do the JSON deserialization in `didReceiveData:` when only part of the data's been received. – Hot Licks Nov 21 '13 at 12:12
  • @Aishvarya... it's not duplicated. There's no connection between this post and that one. – AllMac Nov 21 '13 at 16:47

2 Answers2

1

Your problem is not connected to JSON. Your problem is caused by the fact that data comes in separate chunks and you are trying to parse each chunk as a single JSON object.

You have to join the data chunks into one NSData object (-[NSMutableData appendData:]) and then use a JSON parser to parse them.

Sulthan
  • 128,090
  • 22
  • 218
  • 270
  • Thanx @Sulthan I was not able to append NSData/NSMutableData. Than I was trying to convert do NSString to append. But I solved appending NSMutableData. – AllMac Nov 21 '13 at 16:46
0

If you are getting this JSON from a website, copy the url into http://jsonlint.com to validate it.

Then try using NSJSONSerialization instead of JSONDictionaryExtensions.

NSDictionary *dict = [NSJSONSerialization JSONObjectWithData:data
                                                     options:0
                                                       error:&error];

If that works, then the problem lies in JSONDictionaryExtensions, so you would contact the developer on github that supplied it.

SPA
  • 1,279
  • 8
  • 13