deserialization

How deserialize Byte array to object - Windows 8 / WP 8

爱⌒轻易说出口 提交于 2019-12-23 23:33:46
问题 Hi I use code below to convert object to byte array now I need this byte array convert back to object. Does any one know how to deserialize this in windows 8 app? I find some code but use Serialize and BinaryReader classes and this classes are not in windows 8 or does not know it. Person ps = new Person(); ps.name = "Lucy"; DataContractSerializer serializer = new DataContractSerializer(typeof(List<Dictionary<String, String>>)); byte[] byteArr; using (var ms = new MemoryStream()) { serializer

C#: Deserializing JSON when one field can be different types

允我心安 提交于 2019-12-23 20:34:14
问题 I am communicating with an API that returns JSON containing either true, false or an array of string arrays. I wish to deserialize this JSON and store the boolean value, if there is one, in a class field called Success of data type bool, and the array, if there is one, in a field called Result of a custom data type. What is the best to go about achieving this? Some JSON: [ {"status":"ok","result":true}, { "status":"ok", "result": [ {"name":"John Doe","UserIdentifier":"abc","MaxAccounts":"2"}

Cannot properly memcpy a char array to struct

…衆ロ難τιáo~ 提交于 2019-12-23 20:31:11
问题 So I have a construct called packet struct Packet { unsigned int packet_type; wchar_t packet_length[128]; wchar_t file_name[256]; wchar_t template_name[256]; wchar_t file_name_list[1024]; wchar_t file_data[1024]; void serialize(char * dat) { memcpy(dat, this, sizeof(Packet)); } void deserialize(const char * dat) { memcpy(this, dat, sizeof(Packet)); } }; I'm trying to desieralize from this data {byte[2692]} [0] 0 unsigned int packet_type; (4 bytes) [1] 0 [2] 0 [3] 0 [4] 50 '2' wchar_t packet

serialize/deserialize a list of objects using BinaryFormatter

醉酒当歌 提交于 2019-12-23 20:19:47
问题 I know there were already many discussions on that topic, like this one: BinaryFormatter and Deserialization Complex objects but this looks awfully complicated. What I'm looking for is an easier way to serialize and deserialize a generic List of objects into/from one file. This is what I've tried: public void SaveFile(string fileName) { List<object> objects = new List<object>(); // Add all tree nodes objects.Add(treeView.Nodes.Cast<TreeNode>().ToList()); // Add dictionary (Type: Dictionary

NSData from a custom object

。_饼干妹妹 提交于 2019-12-23 18:38:08
问题 I'm working on client/server application which uses AsyncSocket. For transferring data, it uses NSData . How can I insert my custom object, containing NSNumber s, NSInteger s, and NSString s into an NSData object and then get it back out? 回答1: One way to insert (serialize) a custom object into an NSData object is to use NSCoding and NSKeyedArchiver. First, have your custom object implement the NSCoding protocol. Example here: http://developer.apple.com/library/ios/#documentation/Cocoa

Getting error in gson deserializing using android Studio

社会主义新天地 提交于 2019-12-23 17:23:30
问题 I am working on an application in which I am using android phone contacts in my application.So, for that first of all fetch contact details and store it into ArrayList. After that I serialized that arrayList using gson library and when I deserialize it getting error. I have used gson-2.1.jar for serializing and deserializing contact details. I am getting following error log. AndroidRuntime﹕ FATAL EXCEPTION: main com.google.gson.JsonSyntaxException: java.lang.IllegalStateException: Expected

How to add a SerialVersionUID to a Class[_] instance in Scala?

有些话、适合烂在心里 提交于 2019-12-23 13:23:05
问题 I need to create an instances an instance of java.lang.Class that is otherwise identical to classOf[MyClass] but also has a SerialVersionUID , which MyClass does not have. MyClass is a Scala-2.10 class. One problem is that in Java SerialVersionUID is a static final while in Scala SerialVersionUID since Scala does not have statics. If MyClass was a Java class I think I would be able do this using Javassist: val ctclass = javassist.ClassPool.getDefault().get("mypackagage.MyClass") val field =

Python: performance comparison of using `pickle` or `marshal` and using `re`

喜欢而已 提交于 2019-12-23 13:11:31
问题 I am calculating some very large numbers using Python, and I'd like to store previously calculated results in Berkeley DB. The problem is that Berkeley DB has to use strings, and I have to store an integer tuple for the calculation results. For example, I get (m, n) as my result, one way is to store this as "%d,%d" % (m, n) and read it out using re . I can also store the tuple using pickle or marshal . Which has the better performance? 回答1: For pure speed, marshal will get you the fastest

How to de-serialize XML with many child nodes

有些话、适合烂在心里 提交于 2019-12-23 10:49:11
问题 If my XML is like this: <Item> <Name>Jerry</Name> <Array> <Item> <Name>Joe</Name> </Item> <Item> <Name>Sam</Name> </Item> </Array> </Item> I can serialize it into this class: [DataContract(Namespace = "", Name = "dict")] public class Item { [DataMember(Name = "Name")] public string Name { get; set; } [DataMember(Name = "Array")] public IEnumerable<Item> Children { get; set; } } But what if my XML is like this? <Item> <Name>Jerry</Name> <Item> <Name>Joe</Name> </Item> <Item> <Name>Sam</Name> <

How to deserialize a dictionary using DataContractJsonSerializer?

杀马特。学长 韩版系。学妹 提交于 2019-12-23 10:19:36
问题 I have the following model: [DataContract] public class MessageHeader { private Guid? messageId; public Guid MessageId { get { if (messageId == null) messageId = Guid.NewGuid(); return messageId.Value; } } [DataMember] public string ObjectName { get; set; } [DataMember] public Dictionary<string, object> Parameters { get; set; } // Can't deserialize this [DataMember] public Action Action { get; set; } [DataMember] public User InitiatingUser { get; set; } } Now for some unknown reason,