I have this Json String returned from a web api and stored in a var using JObject.Parse(result);
"{\"Status\":\"0\",\"Message\":\"OK\",\"Count\":\"2\",\"MethodLog\":[{\"ApplicationName\":\"MobileGeneral\",\"CompanySN\":\"0897001\",\"MethodLogCount\":12,\"MethodAccessRefusedCount\":0},{\"ApplicationName\":\"MobileGrain\",\"CompanySN\":\"0897123\",\"MethodLogCount\":900,\"MethodAccessRefusedCount\":0}]}"
I have already created required classes in my workspace:
{
public class MethodLogJson
{
[JsonProperty("Status")]
public string Status { get; set; }
[JsonProperty("Message")]
public string Message { get; set; }
[JsonProperty("Count")]
public string Count { get; set; }
[JsonProperty("MethodLog")]
public List<MethodLog> MethodLog { get; set; }
}
public class MethodLog
{
[JsonProperty("ApplicationName")]
public string ApplicationName { get; set; }
[JsonProperty("CompanySN")]
public string CompanySerial { get; set; }
[JsonProperty("MethodLogCount")]
public string MethodLogCnt { get; set; }
[JsonProperty("MethodAccessRefusedCount")]
public string MethodAccessRefusedCnt { get; set; }
}
}
In my controller I am using:
var resObj = JObject.Parse(result);
var methodLog = JsonConvert.DeserializeObject<MethodLogJson<MethodLog>>(resObj);
But it does not help. Shows me Non-generic Type cannot be used with type arguments. :( Help people!!
MethodLogJsonis a non-generic type - soMethodLogJson<MethodLog>makes no sense. Try justJsonConvert.DeserializeObject<MethodLogJson>(resObj)