我正在使用二进制序列化一个类.我正在使用ios :: append以便将多个对象附加到此文件中.如何检索存储的所有对象?
这是我的测试类,它尝试多个序列化并检索它们.我评论了我没有得到正确数据的失败点.
using namespace std;
class Data {
public:
double get_latitude() const {
return _latitude;
}
double get_longitude() const {
return _longitude;
}
void set_latitude(double _latitude) {
this->_latitude = _latitude;
}
void set_longitude(double _longitude) {
this->_longitude = _longitude;
}
private:
double _latitude;
double _longitude;
friend class boost::serialization::access;
// When the class Archive corresponds to an output archive, the
// & operator is defined similar to <<. Likewise, when the class Archive
// is a type of input archive …Run Code Online (Sandbox Code Playgroud) 我有一个json字符串
{"name":"test","bar":{"name":"testBar"}}
Run Code Online (Sandbox Code Playgroud)
在目标c中我有一个对象
@interface Foo : NSObject {
}
@property (nonatomic, retain) NSString * name;
@property (nonatomic, retain) Bar * bar;
@end
Run Code Online (Sandbox Code Playgroud)
我只是综合了这些属性.我有一个具有综合属性的子对象.
@interface Bar : NSObject {
}
@property (nonatomic, retain) NSString * name;
@end
Run Code Online (Sandbox Code Playgroud)
然后这里是我试图进入Foo对象的代码,其中响应是上面的json字符串:
SBJsonParser *json = [[SBJsonParser new] autorelease];
parsedResponse = [json objectWithString:response error:&error];
Foo * obj = [[Foo new] autorelease];
[obj setValuesForKeysWithDictionary:parsedResponse];
NSLog(@"bar name %@", obj.bar.name);
Run Code Online (Sandbox Code Playgroud)
这会在NSLog语句中引发异常:
-[__NSCFDictionary name]: unrecognized selector sent to instance 0x692ed70'
Run Code Online (Sandbox Code Playgroud)
但是,如果我将代码更改为它的工作原理:
NSLog(@"bar name %@", [obj.bar valueForKey:@"name"]);
Run Code Online (Sandbox Code Playgroud)
我很困惑为什么我不能做第一个例子,或者我做错了什么?