如何使用列表达式识别动态文本



首先,标题可能不太合适。我不太确定如何最好地概括它。我希望这不是误导

我有一个数据表,其中包含一个列,其中包含来自http请求的值。

动态内容1{动态属性}:{姓名}:约翰·多伊},生日}:21年12月24日}2{动态属性}:{姓名}:简·多伊},生日}:21年12月21日}

由于您没有提供更多信息,我让它与DataTable对象一起工作,请注意,这可能不起作用,这取决于您使用的库与数据库通信。

using System;
using System.Data;
using System.Text.Json;
public static void Main()
{
var myDataTable = new DataTable();
myDataTable.Columns.Add("Name", typeof(string));
myDataTable.Columns.Add("Birthday", typeof(DateTime));
foreach(DataRow row in myDataTable.Rows)
{
using JsonDocument doc = JsonDocument.Parse(row["DynamicProperties"].ToString());
var name = doc.RootElement.GetProperty("DynamicProperties")
.GetProperty("Name").GetString();
var birthday = DateTime.ParseExact(doc.RootElement.GetProperty("DynamicProperties")
.GetProperty("Birthday").GetString(), "dd.mm.yyyy", null);

row["Name"] = name;
row["Birthday"] = birthday;
}
}

最新更新