Generically Flatten Json using c#

前端 未结 7 1688
闹比i
闹比i 2020-11-30 02:21

I want to generically flatten some json so I can convert to a datatable and bind to a datagrid using c#

What is the best way of doign it, bearing in mind I dont know

7条回答
  •  眼角桃花
    2020-11-30 03:01

    Another variant using Newtonsoft's Json.NET LINQ to JSON for object at root (the same can be done with JArray also):

    var flattened = JObject.Parse(json)
        .Descendants()
        .OfType()
        .ToDictionary(jv => jv.Path, jv => jv.ToString())
    

提交回复
热议问题