Convert deserialized json class to datatable

前端 未结 3 1003
误落风尘
误落风尘 2021-01-17 05:34

I am trying to convert json that I deserialized to a class to a datatable by using the code below ,however the code below fails at the last line.

using (var          


        
3条回答
  •  被撕碎了的回忆
    2021-01-17 06:00

    If you have only one object serialized then add the square brackets to be parsed to data table correctly.

    var json = JsonConvert.SerializeObject(zone, Formatting.None,
                            new JsonSerializerSettings()
                            {
                                ReferenceLoopHandling = ReferenceLoopHandling.Ignore
                            });
    
    json = "[" + json + "]";
    
    DataTable table = JsonConvert.DeserializeObject(json);
    

提交回复
热议问题