首页 > Web开发 > 详细

Json字符串反序列化

时间:2016-12-16 17:04:51      阅读:277      评论:0      收藏:0      [点我收藏+]
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 引用!

Json字符串反序列化

原文:http://www.cnblogs.com/SuperMetalMax/p/6187313.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!