zoukankan      html  css  js  c++  java
  • 字符串转 Json

    json字符串格式如:

    [{"Title":"第零章","Content":"这是内容信息"},{"Title":" 第一章","Content":"<strong>多云,微风</strong>"},{"Title":" 第二章","Content":"降落伞"},{"Title":" 第三章","Content":"<em><u><span style="color:#006600;">力量</span></u></em>"}]

    asp.net代码:

    protected List<T> ArrayToList<T>(string listStr)
            {
                
                List<T> list = new List<T>();
                if (!string.IsNullOrEmpty(listStr))
                {
                    JArray jsonRsps = JArray.Parse("[" + listStr + "]");
                    for (int i = 0; i < jsonRsps.Count; i++)
                    {
                        JsonSerializer js = new JsonSerializer();
                        T obj = js.Deserialize<T>(jsonRsps[i].CreateReader());
                        list.Add(obj);
                    }
                }
                return list;
            }

    引用到了命名空间:

        using Newtonsoft.Json.Linq;
        using Newtonsoft.Json;

    要转化成的数据实体类:

    public class TestEntity
            {
                public string Title { get; set; }
                public string Content { get; set; }
            }
  • 相关阅读:
    视频遮挡问题
    calc兼容性
    javascript变量声明提升
    jquery插件
    prop和attr在 jquery的
    onclick防止冒泡和json对象放入
    git 入门
    去掉ie滚动条兼容性
    单页面应用程序(SPA)
    swiper轮播图插件
  • 原文地址:https://www.cnblogs.com/wangbogo/p/3117043.html
Copyright © 2011-2022 走看看