使用VB.net和Newtonsoft.Json解析复杂的Json数据

使用VB.net和Newtonsoft.Json解析复杂的Json数据,json,vb.net,winforms,json.net,Json,Vb.net,Winforms,Json.net,我正在使用vb.net构建一个windows应用程序,以获取每天下载的Json文件,并对其进行解析,然后将值输入SQL数据库。我唯一被卡住的部分就是要解析Json数据以获得我需要的值 Public Sub json_parse(ByVal result_json As String) Try Dim json As String = result_json Dim ser As JObject = JObject.Parse(jso

我正在使用vb.net构建一个windows应用程序,以获取每天下载的Json文件,并对其进行解析,然后将值输入SQL数据库。我唯一被卡住的部分就是要解析Json数据以获得我需要的值

Public Sub json_parse(ByVal result_json As String)
        Try
            Dim json As String = result_json
            Dim ser As JObject = JObject.Parse(json)
            Dim data As List(Of JToken) = ser.Children().ToList
            For Each item As JProperty In data
                item.CreateReader()
                Select Case item.Name
                    Case "data"
                        For Each msg As JObject In item.Values
                            MsgBox(msg.ToString)
                        Next
                End Select
            Next
        Catch __unusedException1__ As Exception
            'MsgBox(__unusedException1__.ToString)
        End Try
    End Sub
我试图从以下位置获取上一天、上一天和上一年的值:

数据>mdc_现金价格>数据>工具>其中djShortName=黄金EnglehardFab,djShortName=银EngelhardFab,djShortName=铂金EngelhFab,djShortName=钯EngelFab

我还试图从以下位置获取时间戳的值:

数据>mdc\u现金价格>数据>时间戳

在我当前的代码中,我只能访问第一个数据层

任何帮助都将不胜感激。

请使用类似的工具,以便更轻松地查看

然后简单地

Dim Something as JObject = JObject.Parse(<your JSON>)
因为它是一个数组,所以您可能希望循环它

For Each item In Something("data")("mdc_cashprices")("data")("data")("instruments")
        Something2 = item("last")
Next

顺便说一句,这里有一些格式问题>>>mdc\u现金价格_{\req…感谢您对第一部分的帮助。也许您也可以帮助我完成第二部分。我正在尝试使用以下代码:Dim ser As JObject=JObject.Parseresult_json为serdatamdc_cashprices_datadata Dim timestamp As Strin获取:data>mdc_cashprices_的值g=itemtimestamp gatheredData=timestamp Next,但我一直遇到这个错误:无法访问Newtonsoft.Json.Linq.JProperty上的子值。在timestap上放置一个断点,查看项目是否有意义。如果是,请检查它并查看时间戳位于何处,还请使用更正的o编辑问题中的Json包含的物品:时间戳:7/09/19,看来我可以走了。谢谢你的帮助!
Something1 = Something("data")("mdc_cashprices")("data")("data")("instruments")(0)("last") 'basically you just traverse the levels, you use the id/text for regular stuff (inside {}) and numbers for arrays (inside [])
For Each item In Something("data")("mdc_cashprices")("data")("data")("instruments")
        Something2 = item("last")
Next