当前位置: 代码迷 >> .NET新技术 >> C# json有关问题
  详细解决方案

C# json有关问题

热度:408   发布时间:2016-04-25 01:24:32.0
C# json问题
{
    "totalPage": "20",
    "success": "true",
    "status": "1",
    "Text": "查询",
    "data1": [
        {
            "Id": "1",
            "ClassName": "声母",
            "EnClassName": "Consonant",
            "ClassTime": "2014/12/11 9:06:42",
            "ClassShortcut": "2",
            "ClassCount": "1",
            "ImageUrl": "b.jpg",
            "record": "0/3"
        },
        {
            "Id": "2",
            "ClassName": "韵母",
            "EnClassName": "Vowel",
            "ClassTime": "2014/12/11 9:06:42",
            "ClassShortcut": "2",
            "ClassCount": "2",
            "ImageUrl": "a2.jpg",
            "record": "0/3"
        }
    ],
    "data2": [
        {
            "Id": "3",
            "ClassName": "复韵母",
            "EnClassName": "Compound finals",
            "ClassTime": "2014/12/11 9:06:42",
            "ClassShortcut": "2",
            "ClassCount": "2",
            "ImageUrl": "a3.jpg",
            "record": "0/3"
        },
        {
            "Id": "10",
            "ClassName": "测试",
            "EnClassName": "Shortcut",
            "ClassTime": "2014/12/16 10:44:31",
            "ClassShortcut": "2",
            "ClassCount": "2",
            "ImageUrl": "a10.jpg",
            "record": "0/4"
        },
        {
            "Id": "4",
            "ClassName": "声韵拼合",
            "EnClassName": "Sound",
            "ClassTime": "2014/12/11 9:06:42",
            "ClassShortcut": "2",
            "ClassCount": "3",
            "ImageUrl": "a4.jpg",
            "record": "0/4"
        }
    ]
}
















这样的一个json该如何写
------解决思路----------------------
/// <summary>
        /// 获取分页数据EasyUIJson
        /// </summary>
        /// <param name="dt">数据源</param>
        /// <param name="pn">当前页码</param>
        /// <returns></returns>
        public static string PagerDataToEasyUIJson(DataTable dt, int? pn)
        {
            string strjosn = "";
            if (pn == null)
            {
                pn = 1;
            }

            strjosn += "{\"total\":\"" + PCount + "\",\"page\":\"" + pn + "\",\"rows\":[";
            foreach (DataRow dr in dt.Rows)
            {
                strjosn += "{";
                foreach (DataColumn dc in dr.Table.Columns)
                {
                    strjosn += "\"" + dc.ColumnName + "\":\"" + dr[dc].ToString().Replace("\"", "\\\"") + "\",";
                }
                strjosn = strjosn.Remove(strjosn.Length - 1, 1);
                strjosn += "},";
            }
            if (strjosn.Substring(strjosn.Length - 1) == ",")
            {
                strjosn = strjosn.Remove(strjosn.Length - 1, 1);
            }
            strjosn += "]}";

            return strjosn;
        }
可以模仿我的写法 写。有待改进。你自己改吧。
  相关解决方案