其他分享
首页 > 其他分享> > 匿名对象

匿名对象

作者:互联网

json反射成匿名对象

var list = new List<object>()
{
    new {
            orderSkuList = new[]//orderSkuList是个数组
            {
              new {name="",age="" },
            },
            orderCreateTime = "",
        }
};

var Lists = new List<object>()
{
    list
};

var objJson = new
{
    code = "",
    message = "",
    data = new
    {
        rows = Lists,//rows是个数组
        total = ""
    }
};


string textJson = "{\"code\":\"1\",\"message\":\"操作成功\",\"data\":{\"rows\":[{\"orderSkuList\":[{\"name\":\"朱凯宾\",\"age\":\"12\"}],\"orderCreateTime\":1662007551000},{\"orderSkuList\":[{\"name\":\"刘备\",\"age\":\"12\"},{\"name\":\"张飞\",\"age\":\"12\"}],\"orderCreateTime\":1662007551000}],\"total\":2126}}";

var jj = JsonConvert.DeserializeAnonymousType(textJson, objJson);

Console.WriteLine(jj.code + "\n");

 

标签:orderCreateTime,orderSkuList,name,对象,age,匿名,var,new
来源: https://www.cnblogs.com/ZkbFighting/p/16672821.html