0

我正在尝试将这个字符串:“ "{\"Id\":1,\"Ent\":\"TUROS\",\"Data\":\"2010-09-09\",\"Ap\":\"004510875954\",\"Mat\":\"1129\"}"”反序列化为一个对象,但我发现了这个错误:

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

我的代码:

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


    }
4

1 回答 1

1

DataContractSerializer 用于反序列化 xml。对于 Json,您应该使用DataContractJsonSerializer(只需在您的代码中用 DataContractJsonSerializer 替换 DataContractSerializer,它应该可以工作)或 Json.Net(这会给您更多的灵活性)

于 2013-10-15T13:47:11.377 回答