创build一个与NSJSONSerialization dataWithJSONObject一起使用的对象:options:error:

目前为了使用这个function,我把我的对象“转换”成一个字典。 即属性名称成为键,属性值成为值。

有没有办法正确做到这一点,使一个对象将与此function?

即类似于encodeWithCoderinitWithCoder用于NSUserDefaults

我想做…

 NSData *data = [NSJSONSerialization dataWithJSONObject:myObject options:0 error:nil]; 

此刻我做了一些像…

 NSData *data = [NSJSONSerialization dataWithJSONObject:[myObject dictionaryRepresentation] options:0 error:nil]; 

看看JSONCoding ,它build立在带NSCoding接口的NSJSONSerialization上。