How can I parse a JSON string that would cause illegal C# identifiers?

后端 未结 3 2287
孤城傲影
孤城傲影 2020-11-21 05:24

I have been using NewtonSoft JSON Convert library to parse and convert JSON string to C# objects. But now I have came across a really awkward JSON string and I am unable to

3条回答
  •  甜味超标
    2020-11-21 05:41

    You can use this extensions:

    public static class JsonExtensions
    {
        public static Dictionary ToObject(this string json)
        {
            return JsonConvert.DeserializeObject>(json);
        }
    
        public static string ToJson(this T obj)
        {
            return JsonConvert.SerializeObject(obj);
        }
    }
    

提交回复
热议问题