Re: NSCoding to/from JSON?
Re: NSCoding to/from JSON?
- Subject: Re: NSCoding to/from JSON?
- From: Mike Abdullah <email@hidden>
- Date: Tue, 09 Aug 2011 13:41:42 +0100
I toyed with doing something very similar for plists that might be of interest:
https://github.com/mikeabdullah/KSPropertyListEncoder
On 8 Aug 2011, at 17:56, Jens Alfke wrote:
> Been thinking about archiving NSObjects to/from JSON, using an API similar to NSCoding. I haven’t found any prior art, but I thought I’d ask here.
>
> I am not talking about serializing JSON to/from collection objects a la TouchJSON, JSONKit, etc.; rather, something that lets you convert your custom model objects into JSON and back. And I want it to be clean JSON, so that you can use this API to unarchive JSON created by any of the zillions of web APIs that generate it.
>
> It’s tempting to try to do this using the existing NSArchiving protocol and writing a custom NSKeyed[Un]Archiver subclass. This doesn’t work, at least for my purposes, because JSON has a limited set of data types and I don’t want to clutter up the output with extra type annotations. For example, say the JSON contains a date. JSON doesn’t have a date type, so the convention is to represent the date as a string in ISO-8661 format. But calling -decodeObjectForKey: will return an NSString instead of an NSDate. To get around this you have to add methods like -decodeDateForKey: that make it more clear what you’re expecting. (The same goes for other common value classes like NSData.)
>
> —Jens_______________________________________________
>
> Cocoa-dev mailing list (email@hidden)
>
> Please do not post admin requests or moderator comments to the list.
> Contact the moderators at cocoa-dev-admins(at)lists.apple.com
>
> Help/Unsubscribe/Update your Subscription:
>
> This email sent to email@hidden
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden