Json字符串反序列化

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 引用!

时间: 2024-08-08 09:51:22

Json字符串反序列化的相关文章

C# json字符串反序列化

使用情景:开发中JS传递一个Json格式的字符串到后台,后台将json字符串转化成list集合 1 public static class json 2 { 3 public static List<T> JSONStringToList<T>(this string JsonStr) 4 { 5 JavaScriptSerializer Serializer = new JavaScriptSerializer(); 6 List<T> objs = Serializ

C# Winform反序列化复杂json字符串

最近接的私单是一个CS项目,里面所有的操作都是通过调用API接口来进行的. 接口详细说明 协议:https  请求方式:post  https://xx.xxx.net/app/clients 提交json 数据包 { "action":" food_t_list", "data":{ “pageIndex”:”1”, “pageSize”:”20”, “foodGId”:”1”, “storeId”:”1” } } 返回说明 正确时返回JSON

Memcached中对象反序列化和json字符串用jackson解析成对象的比较

如果项目已经发布,如果临时想对某个在Memcached中的key修改值,那么以对象形式存储的话,将很难修改,但如果以字符串形式存储,通过json解析成对象的话,则会方便很多,因为通过界面往Memcached 添加字符串值是很简单的. 现在来比较一下这两种方式在时间消耗方面的差异: package bean; import java.io.Serializable; public class User implements Serializable{ /** * 序列号 */ private st

Newtonsoft.Json.4.5.0 序列化与反序列化json字符串使用方法总结

在VS里下载安装: Json.NET 5.0.6 http://www.nuget.org/packages/Newtonsoft.Json/5.0.6 反序列化json字符串为List: json字符串如下: 1 {"docs": [{ 2 "uid": 2629577, 3 "nickname": "枕边疯电台", 4 "is_v": "true", 5 "category

Newtonsoft.Json.dll 反序列化JSON字符串

上一篇JSON博客<JSON入门级学习小结--JSON数据结构>中已对JSON做了简单介绍,JSON字符串数组数据样式大概是这样子的: 如今因为项目需求(asp.net web网站,前台向后台传递JSON数据,并对JSON数据处理,详述见博客< <项目经验>--通过js获取前台数据向一般处理程序传递Json数据,并解析Json数据,将前台传来的Json数据写入数据库表中 >),需要对传递的JSON数据反序列化.于是从网上找了许多JSON反序列化的例子,最终决定使用New

[参考]C# JSON字符串序列化与反序列化

C#将对象序列化成JSON字符串 public string GetJsonString() { List<Product> products = new List<Product>(){ new Product(){Name="苹果",Price=5.5}, new Product(){Name="橘子",Price=2.5}, new Product(){Name="干柿子",Price=16.00} }; Produ

C# JSON字符串序列化与反序列化

综合了下面两篇文章. http://www.cnblogs.com/Jan_Dai/archive/2010/11/09/1872821.html http://www.cnblogs.com/dwfbenben/archive/2013/06/06/3122662.html C#对象和json互转 代码 using System;using System.Collections.Generic;using System.IO;using System.Linq;using System.Tex

C++ 基于rapidjson对json字符串的进行序列化与反序列化

json字符串的解析以封装在我们开发过程中经常见到, 尤其在socket通信上面, 在一次项目中碰到json字符串的进行解析, 而公司有没有封装好的库, 于是就自己基于开源的库进行了一次封装, 接下是使用案例, 如果感觉可以, 就去下载我的源代码自己编译一个库出来(能直接编译通过, 无任何依赖), 下载地址: 上传的CSDN资源正在审核当中, 如果现在需要请联系QQ:497725486, 等审核通过, 把链接贴上 jsonObjDefine.h #pragma once #include "..

C#解析JSON字符串总结

JSON文件读取到内存中就是字符串,.NET操作JSON就是生成与解析JSON字符串. 操作JSON通常有以下几种方式: 1. 原始方式:按照JSON字符串自己来解析. 2. 通用方式[★★★★★]:这种方式是使用开源的类库Newtonsoft.Json(下载地址http://json.codeplex.com/).下载后添加dll引用就能用. 首先添加引用:using Newtonsoft.Json; 新增:本地dll下载:Newtonsoft.Json.rar   引用:using Newt