文章出處

using DevComponents.DotNetBar;
using MyControl;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Drawing.Imaging;
using System.IO;
using System.Linq;
using System.Text;
using System.Web.Script.Serialization;
using System.Windows.Forms;

namespace InternetDis
{
    public class clsSystem
    {
        public static T JsonStringToCls<T>(string JsonStr)
        {
            StringReader strReader = new StringReader(JsonStr);
            T clsObj = (T)(new JsonSerializer()).Deserialize(new JsonTextReader(strReader), typeof(T));
            return clsObj;
        }
    }

  public class JsonResult { public string result { get; set; } public string description { get; set; } } }

調用方法:

JsonResult JsonRst = new JsonResult() { result = "-1" };
StreamReader reader = new StreamReader(stream);
string strRst = reader.ReadToEnd();
JsonRst = clsSystem.JsonStringToCls<JsonResult>(strRst);

需要添加 Newtonsoft.Json.dll 引用!


文章列表




Avast logo

Avast 防毒軟體已檢查此封電子郵件的病毒。
www.avast.com


全站熱搜
創作者介紹
創作者 大師兄 的頭像
大師兄

IT工程師數位筆記本

大師兄 發表在 痞客邦 留言(0) 人氣()