/***
* 解读:MyData内Display是List<DisplayInfo>,MyDataObj内Display是List<object>(),然后都有一个Status。二者可以通过转成json串后再转成对方。但是前提是二者内字段名称都必须一模一样(可以不分大小写)
*
*/
static void Main(string[] args)
{
MyDataObj dataObj = new MyDataObj();
dataObj.Status = 2;
dataObj.Display = new List<object>() {
new { ParamCode = "bb" }
};
string a = JsonConvert.SerializeObject(dataObj);//MyDataObj序列号成json using Newtonsoft.Json;
MyData b = JsonConvert.DeserializeObject<MyData>(a);//MyDataObj的json版反序列化成MyData
}
#region
public class MyDataObj
{
public int Status { get; set; }
public List<object> Display { get; set; }
}
public class MyData
{
public int Status { get; set; }
public List<DisplayInfo> Display { get; set; }
}
public class DisplayInfo
{
public string ParamCode { get; set; }
}
#endregion