反序列化时,我得到了这个异常,我检查了提要并且数据成员“播放”没有被重复两次,尽管它确实在 http 响应中显示了两次。
[System.Runtime.Serialization.SerializationException] = {“数据协定类型‘PlayerDetailsSeason’无法反序列化,因为在输入中多次找到数据成员‘played’。”}
我不确定为什么它在 http 响应消息中出现两次。
这是代码
var httpRequest = new HttpRequestMessage(HttpMethod.Get, requestUrl + ConstructRequestContent(requestParams));
var httpClient = new HttpClient();
HttpResponseMessage responseMessage = await httpClient.SendAsync(httpRequest);
if (responseMessage != null && responseMessage.IsSuccessStatusCode) {
Stream stream = await responseMessage.Content.ReadAsStreamAsync();
DataContractJsonSerializer deserializer = new DataContractJsonSerializer(typeof(T));
string contentresponsestr = await responseMessage.Content.ReadAsStringAsync();
//在调查 contentresponsestr 后,我可以看到“played”成员出现了两次。为什么显示两次?
result = (T)deserializer.ReadObject(stream);
}
return result;
} catch (Exception ex)
{
return result;
}