I’m attempting to deserialize the following Json string to c# .net class list collection, but the Jsonconvert.deserialize returns null. Can someone please explain to me what I’m doing wrong.
string strjson = "{ 'TestInfo':[{'testId':1,'testShortDescription':'TankTest','testLongDescription':'Tank Test ','testTypeId':2,'testLimitsId':null},{'testId':2,'testShortDescription':'FuelPump1','testLongDescription':'Fuel Pump 1','testTypeId':4,'testLimitsId':null},{'testId':3,'testShortDescription':'FuelPump2','testLongDescription':'Fuel Pump 2','testTypeId':4,'testLimitsId':null},{'testId':4,'testShortDescription':'TankAudit','testLongDescription':'Tank Chamber Audit','testTypeId':6,'testLimitsId':null}]}";
TestInfoCollectionCS testinfocollection = JsonConvert.DeserializeObject<TestInfoCollectionCS>(strjson);
Here is the collection class:
using System;
using System.Collections.Generic;
using System.Text;
using TestITMobileApp.Model;
namespace TestITMobileApp.App_Data
{
public class TestInfoCollectionCS
{
private List<TestInfoCS> testinfocollection;
public List<TestInfoCS> TestInfoCollection { get => testinfocollection; set => testinfocollection = value; }
}
}
Here is the call:
using System;
using System.Collections.Generic;
using System.ComponentModel;
namespace TestITMobileApp.Model
{
public class TestInfoCS
{
#region "Private variables""
private int testId;
private string testShortDescription;
private string testLongDescription;
private int? testTypeId;
private int? testLimitsId;
#endregion
#region "Properties"
#region "TestID"
public int TestID { get => testId; set => testId = value; }
#endregion
#region "TestShortDescription"
public string TestShortDescription { get => testShortDescription; set => testShortDescription = value; }
#endregion
#region "TestLongDescription"
public string TestLongDescription { get => testLongDescription; set => testLongDescription = value; }
#endregion
#region "TestTypeId"
public int? TestTypeId { get => testTypeId; set => testTypeId = value; }
#endregion
#region "TestLimitsId"
public int? TestLimitsId { get => testLimitsId; set => testLimitsId = value; }
#endregion
#endregion
}
}
What I have tried:
Tried running the above code, but json convert deserialization returns null.