Newtonsoft.Json:JObject 动态添加字段/List<JObject>转DataTable

1.JObject 动态添加字段;

var jsonObject = new JObject();
foreach (var key in Keys)
{
    jsonObject.Add(key, value);
}
jsonObject.Add("*****", "1");

2.  List<JObject>转DataTable

1): 首先List<JObject>转string

List<JObject> jsons = new List<JObject>();
...
string jsonStr = JsonConvert.SerializeObject(jsons);

2): string转DataTable

DataTable table1 = JsonConvert.DeserializeObject<DataTable>(jsonStr);
posted @ 2023-08-28 16:46  新*  阅读(60)  评论(0编辑  收藏  举报