我在JSON文件中有数据:
{
"drivers":
{
"92ca8cf9e45ee61186a6001e671f718d":
{
"DogovorN":"0503770761/10117",
"DogovorData":"Some text",
"DataRozhdenia":"some text",
"MestoRozhdenia":"Some text",
"PassportSeria":"0503",
"PassportN":"770761",
"DataVidachi":"01.03.2004",
"PassportVidan":"Some text",
"Adres":"some text",
"Telefon":"some text",
"RaschetniiSchet":"some text",
"Poluchatel":"some Name",
"Naznachenie":"",
"BIK":"Some text"
}
}
}
我需要添加新记录。像这样:
{
"drivers":
{
"92ca8cf9e45ee61186a6001e671f718d":
{
"DogovorN":"0503770761/10117",
"DogovorData":"01.01.2017",
"DataRozhdenia":"17.12.1983",
"MestoRozhdenia":"с.Ракушка, Ольгинского р-на, Приморского края",
"PassportSeria":"0503",
"PassportN":"770761",
"DataVidachi":"01.03.2004",
"PassportVidan":"Первореченским РУВД г.Владивостока",
"Adres":"г.Владивосток, ул.Днепровская, 14, кв.4",
"Telefon":"9147219161",
"RaschetniiSchet":"40817810250000385310",
"Poluchatel":"Калашников Александр Сергеевич",
"Naznachenie":"",
"BIK":"040813608"
},
"43kj5n43kj5nk5jn6jk36h5j45kb6kj4":
{
"DogovorN":"5664564/676756",
"DogovorData":"Some text",
"DataRozhdenia":"Some text",
"MestoRozhdenia":"Some text",
"PassportSeria":"Some text",
"PassportN":"Some text",
"DataVidachi":"Some text",
"PassportVidan":"Some text",
"Adres":"Some text",
"Telefon":"Some text",
"RaschetniiSchet":"Some text",
"Poluchatel":"Some text",
"Naznachenie":"Some text",
"BIK":"Some text"
}
}}
而且我还需要贬低一些属性值。例如,将“PassportN”的值更改为“92ca8cf9e45ee61186a6001e671f718d”和“123456”。
如何使用Newtonsoft.json在Visual Basic 2015中执行此操作?
阅读代码:(它运作良好,我对阅读没有疑问)
Dim DrvFile As String = File.ReadAllText("Drivers.json")
Dim DrvFileObj As JObject = JObject.Parse(DrvFile)
Dim dataDrvFile As List(Of JToken) = DrvFileObj.Children().ToList
Dim output As String = ""
For Each Driver As JProperty In dataDrvFile
Driver.CreateReader()
Select Case Driver.Name
Case "drivers"
output += "Drivers:" + vbCrLf
Dim drv = Driver.Value
Dim drvProp As List(Of JToken) = drv.Children().ToList
For Each DriverProperty As JProperty In drvProp
Select Case DriverProperty.Name 'e.t.c...
谢谢!