匿名对象

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");

 

posted @ 2022-09-09 14:49  ProZkb  阅读(23)  评论(0编辑  收藏  举报