I have a very simple DataContract class that I need to deserialise into. I'm not using JSON.NET for a particular reason so use DataContractJsonSerializer.
My contract class looks like this
[DataContract(Name = "d")]
public class ResponseClass
{
[DataMember]
public int ResponseCode
{ get; set;}
[DataMember]
public string ResponseMessage
{ get; set;}
[DataMember]
public string Response
{ get; set;}
}
The service call is coming back with a valid Json string, but in deserialising, the value at the end is always 0 or string.Empty despite the value being passed in being non-0 or non string.Empty.
My deserialise code looks like this
private string deserializeJSON(string resp, bool code = false)
{
string value = string.Empty;
ResponseClass deserialized = null;
using (MemoryStream stream = new MemoryStream(System.Text.Encoding.UTF8.GetBytes(resp)))
{
stream.Position = 0;
var ser = new DataContractJsonSerializer(typeof(ResponseClass));
deserialized = ser.ReadObject(stream) as ResponseClass;
}
value = code ? deserialized.Response : deserialized.ResponseCode.ToString();
return value;
}
I've looked around for an answer on this but nothing is springing back.
The data back looks like this (which is why the contract back is called "d" - not sure if that makes a difference or not, but the result is still the same, RespCode is 0, RespMess,Resp = string.Empty)
{
"d":
{
"RespCode": 0,
"RespMess": null,
"Resp": null
}
}
private string deserializeJSON(string resp, bool code = false)method?