我试图从json文件向现有对象添加新属性。我想添加一个存储在json文件中的新配置文件
这是文件的json结构。
你知道,我需要追求:"个人资料":{并在这里添加内容,复制其中一个配置文件结构并将其粘贴到新数据中。恩。 " NEW PROFILE NAME":{" name":" NEW PROFILE NAME"," lastVersionId":" VERSION ID"
这是我到目前为止所做的,但不知道如何处理它,也许你会理解
Imports System.IO
Imports Newtonsoft
Imports Newtonsoft.Json
Imports Newtonsoft.Json.Linq
Module Module1
Sub Main()
Dim reader As New StreamReader("C:\Launcher_Profiles.json")
Dim jsonData As String = reader.ReadToEnd
reader.Close()
'At this point we have the json data in a string variable, parse it and enumerate
'each token in the parent "objects" and if it starts with realms we will add a new
'MinecraftData object to a list of MinecraftData objects
Dim allData As JObject = JObject.Parse(jsonData)
Dim minecraftDataList As New List(Of ProfileData)
For Each token As JToken In allData("objects")
Dim prop As JProperty = token
If prop.Name.StartsWith("profiles") Then
minecraftDataList.Add(New ProfileData With {.ProfileName = prop.Name, .ProfileVersion = prop.Value("ProfileVersion"), .Size = prop.Value("size")})
End If
Next
'Now you have all of the data in the minecraftDataList
For Each md As ProfileData In minecraftDataList
Console.WriteLine(md.ProfileName)
Console.WriteLine(md.ProfileVersion)
Console.WriteLine(md.Size)
Console.WriteLine()
Next
Console.ReadLine()
End Sub
End Module