Serialize and Deserialize Objective-C objects into JSON

后端 未结 7 1773
花落未央
花落未央 2020-11-30 01:05

I need to serialize and deserialize objective-c objects into JSON to store in CouchDB. Do people have any example code for best practice for a general solution? I looked a

7条回答
  •  天命终不由人
    2020-11-30 01:48

    It sounds like you're looking for a serialization library that can let you convert objects of your own custom classes into JSON, and then reconstitute them back. Serialization of property-list types (NSArray, NSNumber, etc.) already exists in 3rd party libraries, and is even built into OS X 10.7 and iOS 5.

    So, I think the answer is basically "no". I asked this exact question a month or two ago on the cocoa-dev mailing list, and the closest I got to a hit was from Mike Abdullah, pointing to an experimental library he'd written:

    https://github.com/mikeabdullah/KSPropertyListEncoder

    This archives objects to in-memory property lists, but as I said there are already APIs for converting those into JSON.

    There's also a commercial app called Objectify that claims to be able to do something similar:

    http://tigerbears.com/objectify/

    It's possible I'll end up implementing what you're asking for as part of my CouchCocoa library, but I haven't dived into that task yet.

    https://github.com/couchbaselabs/CouchCocoa

提交回复
热议问题