Rob Williams is a probabilistic Lean coder of Java and Objective-C. Rob is a DZone MVB and is not an employee of DZone and has posted 141 posts at DZone. You can read more from them at their website. View Full User Profile

Finally, the JSON Encoder

06.20.2012
| 2394 views |
  • submit to reddit
I did this post quite a while ago about my experiences in using JSON to connect iPhone/iPad apps to a backend. At the time, I found sbjson, but was unhappy with the fact that it ignored the NSCoding protocol, and thus, it ended up insinuating itself into a large part of your codebase. So my original solution was to use sbjson, but only in one place: where the encoder and decoder need to handle JSON. I said I would open source it and never did (despite a lot of people asking for it). The main reason was I just didn‘t get around to preparing it and I wanted an even better solution.

Well, in the meantime, I found out not long ago that Apple added a class to the iOS SDK that handles JSON! So at long last, here is an NSCoding implementation that has no other dependencies and lets you serialize your entities to and from JSON with ease.

Of course, it‘s housed on GitHub. I didn‘t add a license agreement but am releasing it free of any restrictions (MIT).

JSONEncoder

Published at DZone with permission of Rob Williams, author and DZone MVB. (source)

(Note: Opinions expressed in this article and its replies are the opinions of their respective authors and not those of DZone, Inc.)