【发布时间】:2019-09-24 05:27:55
【问题描述】:
我在 JSON 文件中有数据,我想将其复制到 SQL 表中。
这是我的 JSON 文件数据:
{
"SuccessResponse": {
"Head": {
"RequestId": "A1",
"RequestAction": "GetBrands",
"ResponseType": "Brands",
"Timestamp": "2019-09-23T22:43:08-05:00"
},
"Body": {
"Brands": [
{
"BrandId": 23885,
"Name": "Brand 1",
"GlobalIdentifier": "B1"
},
{
"BrandId": 23886,
"Name": "Brand 2",
"GlobalIdentifier": "B2"
},
{
"BrandId": 23887,
"Name": "Brand 3",
"GlobalIdentifier": "B3"
}
]
}
}
}
我已经弄清楚如何使用数组提取数据,但是我想将上述JSON文件中的所有数据记录复制到SQL表中。
Dim x As String = "{'products':[{'title':'Mouse','price':'20$'},{'title':'KeyBoard','price':'30$'}]}"
Dim result = JsonConvert.DeserializeObject(x)
Console.WriteLine(result("products")(0)("title") & " - " & result("products")(0)("price"))
Console.WriteLine(result("products")(1)("title") & " - " & result("products")(1)("price"))
我从上面的代码得到如下结果:
Mouse - 20$
KeyBoard - 30$
【问题讨论】:
-
请编辑问题而不是添加 cmets。
-
您可以查看此问题中发布的解决方案:stackoverflow.com/questions/12634516/…。
-
感谢您的反馈,您分享的主题是将数据保存到 Sql 但我希望将我的 JSON 文件数据脱盐并复制到 SQL 数据库中。..
-
@SajidSoomro “将数据保存到 Sql ”和“复制到 SQL 数据库”有什么区别?
-
@Mary 完全没有区别,但是我需要我的程序来转换 JSON 脚本中的数据并将其保存到数据库字段中。