标签:反序列化 soft bsp static newton var turn init 调用
添加第三方引用
using Newtonsoft.Json;
/// <summary>
/// 匿名类型解析
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="jsonString"></param>
/// <param name="anonymousTypeObject"></param>
/// <returns></returns>
public static T DeserializeAnonymousType<T>(string jsonString, T anonymousTypeObject)
{
return JsonConvert.DeserializeAnonymousType(jsonString, anonymousTypeObject);
}
调用方,无需专门定义一个类
string jsonString="";
var definition = new { name= "", sex= "", age= "" };
var encryptObject = JsonHelper.DeserializeAnonymousType(jsonString, definition);
// 获取数据
string name= encryptObject.name;
string sex= encryptObject.sex;
string age= encryptObject.age;
标签:反序列化 soft bsp static newton var turn init 调用
原文地址:http://www.cnblogs.com/big-god/p/6752666.html