xxyy
2025-03-05 6d578d016127db97d6f981ff18614ef52a2e0ede
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
 
namespace WIDESEA_Cache;
/// <summary>
/// object拓展
/// </summary>
public static class ObjectExtension
{
    /// <summary>
    /// json字符串序列化
    /// </summary>
    /// <param name="json"></param>
    /// <returns></returns>
    public static object ToObject(this string json)
    {
        return string.IsNullOrEmpty(json) ? null : JsonConvert.DeserializeObject(json);
    }
 
    /// <summary>
    /// json字符串序列化
    /// </summary>
    /// <typeparam name="T"></typeparam>
    /// <param name="json"></param>
    /// <returns></returns>
    public static T ToObject<T>(this string json)
    {
        if (json != null)
        {
            json = json.Replace("&nbsp;", "");
            return JsonConvert.DeserializeObject<T>(json);
        }
        else return default;
    }
 
    /// <summary>
    /// json字符串序列化
    /// </summary>
    /// <param name="json"></param>
    /// <returns></returns>
    public static JObject ToJObject(this string json)
    {
        return json == null ? JObject.Parse("{}") : JObject.Parse(json.Replace("&nbsp;", ""));
    }
}