You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
32 lines
926 B
32 lines
926 B
using Newtonsoft.Json;
|
|
using Newtonsoft.Json.Linq;
|
|
using System;
|
|
|
|
namespace Wood.Util
|
|
{
|
|
#region JsonHelper
|
|
public static class JsonHelper
|
|
{
|
|
public static T? ToObject<T>(this string Json)
|
|
{
|
|
Json = Json.Replace(" ", "");
|
|
return Json == null ? default(T) : Newtonsoft.Json.JsonConvert.DeserializeObject<T>(Json);
|
|
}
|
|
|
|
public static JObject ToJObject(this string Json)
|
|
{
|
|
return Json == null ? JObject.Parse("{}") : JObject.Parse(Json.Replace(" ", ""));
|
|
}
|
|
|
|
public static JArray ToJArray(this string Json)
|
|
{
|
|
return Json == null ? JArray.Parse("[]") : JArray.Parse(Json.Replace(" ", ""));
|
|
}
|
|
|
|
public static string ToJson(this object obj)
|
|
{
|
|
return obj == null ? string.Empty: Newtonsoft.Json.JsonConvert.SerializeObject(obj);
|
|
}
|
|
}
|
|
#endregion
|
|
}
|
|
|