Json字符串与类的转换
来源:互联网 发布:几种搜索引擎算法比较 编辑:程序博客网 时间:2024/06/05 06:15
using Newtonsoft.Json;
using System.Runtime.Serialization.Json;
using System.IO;
public static T JsonToObject<T>(string jsonString)
{
DataContractJsonSerializer ser = new DataContractJsonSerializer(typeof(T));
MemoryStream ms = new MemoryStream(Encoding.UTF8.GetBytes(jsonString));
T jsonObject = (T)ser.ReadObject(ms);
ms.Close();
return jsonObject;
}
public static string ObjectToJson<T>(T jsonObject)
{
DataContractJsonSerializer ser = new DataContractJsonSerializer(typeof(T));
MemoryStream ms = new MemoryStream();
ser.WriteObject(ms, jsonObject);
// T jo = (T)ser.ReadObject(ms);
System.IO.StreamReader reader = new StreamReader(ms);
ms.Position = 0;
string strRes = reader.ReadToEnd();
reader.Close();
ms.Close();
return strRes;
}
- Json字符串与类的转换
- Json字符串与json对象的转换
- json字符串与json对象的转换
- json与字符串转换
- json对象与json字符串的转换,json字符串与java对象的转换
- ASP.NET JSON字符串与实体类的互转换
- ASP.NET JSON字符串与实体类的互转换
- json对象与字符串之间的转换
- JSON 字符串 与 java 对象的转换
- JSON 字符串 与 java 对象的转换
- JSON 字符串 与 java 对象的转换
- JSON 字符串 与 java 对象的转换
- JSON 字符串 与 java 对象的转换
- JSON 字符串 与 java 对象的转换
- JSON 字符串 与 java 对象的转换
- JSON 字符串 与 java 对象的转换
- JSON 字符串 与 java 对象的转换
- JSON 字符串 与 java 对象的转换
- Java 内存模型与线程
- zzulioj 1895: 985的0-1串难题
- WireShark 过滤语法使用
- ov9712_cmos.c代码
- 常用去除警告的方法
- Json字符串与类的转换
- Unity3d爬坑记之旧版动画animation动画还原
- Java 命令行运行参数大全
- 如何用技术服务我们的生活
- windows命令行常用命令
- hibernate 之HQL查询实例
- Wi-Fi Calling
- 快速修图术语学习
- UML中箭头含义