r-magalhaes
r-magalhaes

Reputation: 458

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);


    }

Upvotes: 0

Views: 79

Answers (1)

Benoit Catherinet
Benoit Catherinet

Reputation: 3345

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)

Upvotes: 1

Related Questions