在MonoTouch的,是有可能一个泛型列表保存到NSUserDefaults的到? [英] In Monotouch, is it possible to save a generic list to to NSUserDefaults?
问题描述
我有一个名单,其中,哈希表>
在我的MonoTouch的应用程序,我需要把它坚持到我的设置。 NSUserDefaults的
,但是,只需要在从 NSObject的
继承的东西。
I have a List<Hashtable>
in my MonoTouch app, and I need to persist it to my settings. NSUserDefaults
, however, only takes in things that inherit from NSObject
.
有没有一种简单的方法来包装在我的清单中的 NSObject的
我可以在我的设置存储,或者是一个快速通用的方法来连接code和德codeA 的Hashtable
来一个JSON字符串(或类似)?
Is there a simple way to wrap my List in an NSObject
that I can store in my settings, or is a quick generic way to encode and decode a Hashtable
to a JSON string (or similar)?
还是有MonoTouch的替代坚持的Hashtable
S'
Or is there a MonoTouch alternative for persisting a small list of Hashtable
s?
推荐答案
就像@Maxim说,有几种方法可用。如果你想使用 NSUserDefaults的
来存储数据,那么你可以将其序列化(一个.NET功能可供您使用MonoTouch的)来完成:
Like @Maxim said there are several approach available. If you want to use NSUserDefaults
to store your data then you can serialize it (a .NET feature available to you using MonoTouch) to either:
-
二进制格式。然后使用
流
(或字节[]
)来创建一个的NSData code>实例you'l能够存储与
NSUserDefaults的
;或
a binary format. Then use the
Stream
(orbyte[]
) to create anNSData
instance that you'l be able to store withNSUserDefaults
; or
成字符串,并将其保存为一个的NSString
(字符串
重载也可以,但它会做的NSString
转换);
into a string and store it as a NSString
(string
overloads are also available, but it will do the NSString
conversion);
这篇关于在MonoTouch的,是有可能一个泛型列表保存到NSUserDefaults的到?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!