Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我的应用程序需要通过 HTTP 将自定义对象序列化到远程数据库。将对象转换为可以通过 http 发送的格式的最佳方法是什么?我的应用程序使用 Core Data 在内部存储数据。
使用实体的属性值创建一个 NSDictionary 对象,其中键是属性名称,值是字典的对象。使用 NSJSONSerialization 序列化字典并创建一个 NSData。将此数据用作您发送的请求的 httpbody。
文档:http: //developer.apple.com/library/ios/#documentation/Foundation/Reference/NSJSONSerialization_Class/Reference/Reference.html
https://developer.apple.com/library/mac/#documentation/Cocoa/Reference/Foundation/Classes/nsdictionary_Class/Reference/Reference.html
https://developer.apple.com/library/mac/#documentation/Cocoa/Reference/Foundation/Classes/NSMutableURLRequest_Class/Reference/Reference.html