0

I'm working in Xcode 4.3.2 + building for an app in iOS 5.

I've decided to use SBJson to parse streams of data from our server. I've verified that I'm receiving a valid JSON response from the server. My question concerns the design behind the classes SBJsonStreamParser and the SBJsonParser.

It appears that in SBJsonParser the method "objectWithData" takes the data received from the JSON response and uses the SBJsonStreamParserAccumulator to append the stream of data into a single JSON document. Once the data stream is gathered into one object, it is then parsed by the "parse" method in SBJsonStreamParser.

I've run into several issues when requesting larger JSON documents. The size of the responses seem to be reasonable (specially 9.4 KB response). It appears that the SBJsonStreamParser breaks when getting a data stream greater than a certain size. The parser succeeds when the response is small (~3KB), but fails when the response is larger (~10KB). I used NSLog to verify that in both cases, pulling a small & large stream, the methods are successfully receiving the full json document - because it looks like [{"id": .... 123}]. I'm convinced that the issue is that the data stream is too long.

I'm wondering if I'm using SBJson incorrectly or is this simply a limitation of the parser? Is there anything that I can configure that allows SBJsonStreamParser to not throw an error for larger (but reasonable) data streams & continue to parse the full response?

Thanks in advance!

Henry
  • 926
  • 2
  • 12
  • 27
  • What error is reported by SBJson? – Stig Brautaset Sep 26 '12 at 20:52
  • In SBJsonParser, in the switch statement in "objectWithData" the error is SBJsonStreamParserError case is returning the error. In SBJsonStreamParser, the sbjson_token_error switch case is being returned. – Henry Sep 26 '12 at 21:09
  • What's the error message string? It might give a hint... – Stig Brautaset Sep 26 '12 at 22:01
  • There isn't actually an error message. I just know that an error switch is entered into. I'm not sure what I'm missing from my explanation. – Henry Sep 26 '12 at 22:06
  • Please check the error property on SBJsonStreamParser / SBJsonParser (whichever you're using). If the parser fails but doesn't set the error property I'd be *very* interested in seeing a reproducible test case posted to https://github.com/stig/json-framework/issues, as that would be a bug. – Stig Brautaset Sep 26 '12 at 22:16
  • let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/17204/discussion-between-stig-brautaset-and-henry) – Stig Brautaset Sep 26 '12 at 22:22

1 Answers1

1

Actually you have the workings of objectWithData: backwards. SBJsonStreamParserAccumulator is used to accumulate the parsed output, not the unparsed data stream.

Stig Brautaset
  • 2,602
  • 1
  • 22
  • 39
  • I'm just curious. Are you able to parse JSON responses that are ~10KB? – Henry Sep 26 '12 at 22:59
  • Yes. The test suite parses a stream of data that is 100KB long, and if you build the TweetStream example project that will parse a stream of JSON that never finishes downloading. – Stig Brautaset Sep 26 '12 at 23:14