简体   繁体   中英

Error on Deserializing on windows phone 7

i'm trying deserializing this string: " "{\\"Id\\":1,\\"Ent\\":\\"TUROS\\",\\"Data\\":\\"2010-09-09\\",\\"Ap\\":\\"004510875954\\",\\"Mat\\":\\"1129\\"}" " to an object, but i catch this error:

There was an error deserializing the object of type Seguro. Data at the root level is invalid. Line 1, position 1.

My code:

private void sendPostCompleted(object sender, UploadStringCompletedEventArgs e)
    {
        // Handle result

        var status = e.Result;
        byte[] data = Encoding.UTF8.GetBytes(status);
        MemoryStream memStream = new MemoryStream(data);
        DataContractSerializer serializer = new DataContractSerializer(typeof(Seguro));
        Seguro car = (Seguro)serializer.ReadObject(memStream);


    }

The DataContractSerializer is to be used to deserialize xml. For Json you should use DataContractJsonSerializer (Just replace DataContractSerializer by DataContractJsonSerializer in your code and it should work) or Json.Net (which will give you a little more flexibility)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM