

Parsing JSON in iOS the right way - adam0101
http://remarkablepixels.squarespace.com/blog/2010/12/20/parsing-json-in-ios-the-right-way.html

======
BarkMore
The author is using a library that parses an entire JSON document in one go.
In order to use this library, the author points out that the application must
collect the entire document from the network before parsing the document. It
does not work if the application passes chunks of the document to the parser.

An alternative approach is to use an incremental parser like YAJL. The
application can feed chunks of the JSON document to the parser as the chunks
arrive over the network. A clever application can update the UI before the
entire document is received by examining the partially constructed object
tree.

~~~
adam0101
Right but for people new to iOS dev is this really the best way? Instead of
giving a caveat why not give a solution that will work in all situations?

~~~
BarkMore
There's no caveat for using YAJL. An application can feed data to YAJL from
connection:didReceiveData: and know that the document is complete in
connectionDidFinish:. This works if there are one or many calls to
connection:didReceiveData:.

Anybody new to iOS needs to learn that connection:didReceiveData: is called as
data is received. There's no way around that. There are two ways to deal with
this. The first is to buffer the data as the author suggests. The other
approach is to use an incremental parser.

------
imcqueen
Good post. I think the same holds true for the NSXMLParser delegate (and
probably many others, I'm still new to iOS).

The "foundCharacters" method is sometimes called multiple times before
reaching the end of an element so it's best to assume you're receiving only
part of the data.

