在Monotouch中寻找NSKeyedUnarchiver的帮助
在SQLite blob字段中存储字典项数组
IOS代码
NSData *data = [[NSData alloc] initWithBytes:ptr length:size];
NSKeyedUnarchiver *unarchiver = [[NSKeyedUnarchiver alloc] initForReadingWithData:data];
NSMutableArray *myArray = [unarchiver decodeObjectForKey:@"pricing"];
[unarchiver finishDecoding];
NSMutableArray *MutData = [[NSMutableArray alloc] init];
for (NSDictionary *obj in myArray) {
NSMutableDictionary *element = [[NSMutableDictionary alloc] initWithDictionary:obj];
[MutData addObject:element];
}尝试转换为MonoTouch,到目前为止我已经
MonoTouch码
NSData data = NSData.FromString(item.pricing);
NSKeyedUnarchiver unarchive = new NSKeyedUnarchiver(data);
unarchive.DecodeObject();
unarchive.FinishDecoding();
NSMutableArray array = unarchive.GetNativeField("pricing") as NSMutableArray;
NSMutableArray mutArray = new NSMutableArray();
for (uint count=0; count < array.Count; count++)
{
NSMutableDictionary mutDict = new NSMutableDictionary(array.ValueAt(count));
mutArray.Add(mutDict);
}在运行时生成和错误
未处理的托管异常:Objective异常抛出。名称:* /Developer/MonoTouch/Source/monotouch/src/Foundation/NSKeyedUnarchiver.g.cs:88 initForReadingWithData:* -NSKeyedUnarchiver initForReadingWithData::无法理解的存档(0x62、0x70、0x6c、0x69、0x73、0x74、0x30、0x30) (MonoTouch.Foundation.MonoTouchException)位于MonoTouch.Foundation.NSKeyedUnarchiver..ctor (MonoTouch.Foundation.NSData data) 0x00027 at MonoTouch.Foundation.NSKeyedUnarchiver..ctor(MonoTouch.Foundation.NSData data)
来自新的NSKeyedUnarchiver(数据)行
有人能为MonoTouch NSKeyedUnarchiver推荐教程/示例吗?
有人能帮我解决这个错误吗?
最后,这是实现该项目跨平台并在Android (最终)下工作的最佳方式吗?
提前感谢
发布于 2013-04-13 03:21:23
问题可能在于您如何创建初始NSData。
这是NSData.FromString所做的,它看起来不太像在Objetive-C中所做的工作。
如果在C#中有可用的指针,请尝试使用NSData.FromBytes。
https://stackoverflow.com/questions/15972792
复制相似问题