Json字符串反序列化
2024-10-15 19:57:34
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 引用!
最新文章
- Android开发学习—— ContentProvider内容提供者
- 东大OJ-1040-Count-快速幂方法求解斐波那契-
- 安装ubuntu和安装ubuntu后要安装的软件列表
- 两种不同png图片的在项目中的运用
- 使用Spring的注解方式实现AOP
- Lintcode: Majority Number II
- Git客户端TortoiseGit(Windows系统)的使用方法
- WCF服务的创建和发布到IIS
- windows store app promise
- Objective C 链式调用
- 不忘初心 --- 重读<;<;The C Programming Language>;>;
- Linux入门之常用命令(11) 系统监控 vmstat top
- python的枚举
- Kibana安全特性之权限控制
- Ordering Tasks
- Spring各个jar包作用
- 第三个Sprint冲刺第八天(燃尽图)
- scala-泛型
- Selenium+Java自动化测试的方法
- Unity中进程间通信——使用异步Socket
热门文章
- Web端导出CSV
- 用于主题检测的临时日志(431b1c14-8b75-4f42-994f-cfda72208c10 - 3bfe001a-32de-4114-a6b4-4005b770f6d7)
- C#Light(包括unity一切C#环境可用嵌入式脚本)0.10B稳定版发布,功能已定型
- java加密-解密小结
- WebViewJavascriptBridge的暂时理解
- Android开发学习之路-Android Design Support Library使用(CoordinatorLayout的使用)
- atitit &#160;opencv apiattilax总结&#160;约500个函数 .xlsx
- tabs左右滚动
- vue-cli创建项目
- 查看Wait type