Json反序列化为动态类型(dynamic)可转换List<dynamic>

原文章
https://www.cnblogs.com/zhyue93/p/json_Deserialize.html

/// <summary>
/// 反序列化json字符串
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="jsonText"></param>
/// <returns></returns>
public static T FromJson<T>(string jsonText)
{
    var json = new JsonSerializer
    {
        NullValueHandling = NullValueHandling.Ignore,
        ObjectCreationHandling = ObjectCreationHandling.Replace,
        MissingMemberHandling = MissingMemberHandling.Ignore,
        ReferenceLoopHandling = ReferenceLoopHandling.Ignore
    };

    var sr = new StringReader(jsonText);
    var reader = new JsonTextReader(sr);
    var result = (T)json.Deserialize(reader, typeof(T));
    reader.Close();

    return result;
}
string jsonData = "{\"column\":\"1\"}";//,\"rows\":\"4\"
dynamic jsonObj = JsonHelper.FromJson<dynamic>(jsonData);
//List<dynamic>jsonObj = JsonHelper.FromJson<List<dynamic>>(jsonData);
string rows = jsonObj.rows;//不会报错 结果为null
Console.WriteLine(rows);
Console.ReadKey();
``` <% List<test_information> list = (List<test_information>)session.getAttribute("date"); String jsonString = new com.google.gson.Gson().toJson(list); %> <div id="overlay" style="display:none; position:fixed; top:0; left:0; width:100%; height:100%; background-color:rgba(0,0,0,0.5); z-index:99;"></div> <div class = "tit">查看凭证</div> <div class = "Ribbon"> <table class = "R_t"> <tr> <td style="white-space: nowrap; border-right: none !important;" class = "left_Ribbon"> <!-- 按钮1 --> <input type="button" value="传统记账" class="R_button_1" onclick = "accounting.show()"> <!-- 表单2 - 导出 --> <form action="" class="inline-form"> <input type="submit" value="导出" class="R_button"> </form> <!-- 表单3 - 打印 --> <form id="printForm" action="white.jsp" method="post" class="inline-form"> <input type="hidden" id="selectedTelsHiddenField" name="telsToPrint"> <input type="submit" value="打印" onclick="return submitSelectedTels();" class="R_button"> </form> <!-- 按钮4 --> <input type="button" value="模板" onclick="template.show()" class="R_button"> </td> <td class = "search_box"> <input type = "text" name = "search_name"class = "search_text" placeholder = "搜索关键字"> <input type="button" value="搜索" onclick="performSearch()" class = "search_button"> </td> </tr> </table> </div> <div class="body"> <table class="cer" > <% for(test_information news:list) { %> <!-- 将每条记录分为两列展示 --> <tr class = "head_tr"> <td class="zero_box"> <input type="checkbox" name="selectedTels" value="<%=news.getTel()%>" onchange="updateSelection(this)" style = "zoom : 300%"> </td> <td class="first_box"> <table> <tr> <td class="material_box"><%= news.getMaterial() %></td> </tr> <tr> <td class="time_box"><%= news.getStart_time() %></td> </tr> </table> </td> <td class="second_box"> <%= news.getWashing_method() %> <br/> <%= news.getPrice() %> </td> <td class="third_box"> <form action =""> <input name = "id" value ="<%=news.getTel() %>" type = "hidden"> <input type ="submit" class = "func_button" value = "税费" ><br> <input type ="submit" class = "func_button" value = "查看凭证" ><br> <input type ="submit" class = "func_button" value = "删除凭证" > </form> </td> </tr> <% } %> </table>```怎么解决吧list转换json格式后再table中的for循环无法使用的问题
最新发布
03-20
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值