Answer the question
In order to leave comments, you need to log in
How to parse json in .net?
Forced to use DataContractJsonSerializer
such json
class
{"ErrorMessage":""}
[DataContract]
public class ResultScanResponse
{
[DataMember(Name = "ErrorMessage")]
public string ErrorMessage { get; set; }
}
public static T Deserialize<T>(string aJSON) where T : new()
{
T deserializedObj = new T();
MemoryStream ms = new MemoryStream(Encoding.UTF8.GetBytes(aJSON));
DataContractJsonSerializer ser = new DataContractJsonSerializer(aJSON.GetType());
deserializedObj = (T)ser.ReadObject(ms);
ms.Close();
return deserializedObj;
}
Answer the question
In order to leave comments, you need to log in
public static T Deserialize<T>(string aJSON) where T : new()
{
var ms = new MemoryStream(Encoding.UTF8.GetBytes(aJSON));
var ser = new DataContractJsonSerializer(typeof(T));
var deserializedObj = (T)ser.ReadObject(ms);
ms.Close();
return deserializedObj;
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question