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.WriteObject(ms, ps.name);
            byteArr = ms.ToArray();
        }
        tbByteResult.Text = byteArr.ToString();

回答1:


Try:

    using (var ms = new MemoryStream(byteArr))
    {
        var yourObject = serializer.ReadObject(ms);
    }


来源:https://stackoverflow.com/questions/17671702/how-deserialize-byte-array-to-object-windows-8-wp-8

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!