qinjie
2023-11-23 1c0be3112f45f4cb10f2fb41398407a3b4de5bc1
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
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
 
 
 
namespace Hydro.CommonBase
{
    public class json
    {
        public static dynamic loads(string s)
        {
            try
            {
                return JsonConvert.DeserializeObject<JObject>(s).Todict() as dict;
 
            }
            catch
            {
                return JsonConvert.DeserializeObject<List<string>>(s);
            }
        }
 
        public static string dumps(object s)
        {
            try
            {
                return JsonConvert.SerializeObject(s);
            }
            catch
            {
                return JsonConvert.SerializeObject(s);
            }
        }
    }
}