服务端相关代码也合并到仓库
This commit is contained in:
1 parent
fef54e1f0f
commit
879b72e21a
32 files changed
+3626
-1
No files matched your search
@@ -0,0 +1,47 @@
|
||||
using Newtonsoft.Json;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Web;
|
||||
|
||||
namespace KJD_Web.Utils
|
||||
{
|
||||
public class JsonUtils
|
||||
{
|
||||
/// <summary>
|
||||
/// 反序列化Json字符串生成对象实体
|
||||
/// </summary>
|
||||
/// <typeparam name="T">对象类型</typeparam>
|
||||
/// <param name="jsonStr">json字符串</param>
|
||||
/// <returns>对象实体</returns>
|
||||
public static T DeserializeJsonToObject<T>(string jsonStr) where T : class
|
||||
{
|
||||
try
|
||||
{
|
||||
JsonSerializer serializer = new JsonSerializer();
|
||||
StringReader sr = new StringReader(jsonStr);
|
||||
object obj = serializer.Deserialize(new JsonTextReader(sr), typeof(T));
|
||||
T t = obj as T;
|
||||
return t;
|
||||
}
|
||||
catch
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public static string SerializerObjectToString(object obj)
|
||||
{
|
||||
try
|
||||
{
|
||||
string str = JsonConvert.SerializeObject(obj, Formatting.None);
|
||||
return str;
|
||||
}
|
||||
catch
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user