使用" Newtonsoft"在VB.NET中解析Json Json.net

时间:2018-01-21 13:29:45

标签: json vb.net json.net

如何在vb.net中解析Json;想创建bittrex自动收报机。

请求我使用以下代码:

  Dim request As HttpWebRequest
    Dim response As HttpWebResponse = Nothing
    Dim reader As StreamReader

    Try

        request = DirectCast(WebRequest.Create("https://bittrex.com/api/v1.1/public/getmarketsummary?market=btc-ltc"), HttpWebRequest)
        response = DirectCast(request.GetResponse(), HttpWebResponse)
        reader = New StreamReader(response.GetResponseStream())


        rawresp = reader.ReadToEnd()


    Catch ex As Exception
        Console.WriteLine(ex.ToString)
        MsgBox(ex.ToString)
    Finally
        If Not response Is Nothing Then response.Close()
    End Try

我得到了json的回应:

{"success":true,"message":"","result":[{"MarketName":"BTC-LTC","High":0.01670094,"Low":0.01610000,"Volume":47495.02156742,"Last":0.01628948,"BaseVolume":777.22088098,"TimeStamp":"2018-01-21T13:18:23","Bid":0.01624001,"Ask":0.01628948,"OpenBuyOrders":2146,"OpenSellOrders":8104,"PrevDay":0.01622000,"Created":"2014-02-13T00:00:00"}]}

希望Last的值显示在文本框中,所以我尝试用" Newtonsoft"解析它。如下:

  Dim jsonArray As JArray = JArray.Parse(rawresp)
    For Each item As JObject In jsonArray
        textboxLast.Text = item.SelectToken("Last").ToString

    Next

但是得到错误:(

1 个答案:

答案 0 :(得分:0)

session_start();

// assigning the user-object here is not necessary, it is unserialized
$user = $_SESSION["User"];

// I assume your user-object actually has a method 'test'
$user->test();

它与JSON的格式有关。它不是一个数组,而是一个包含数组的对象,因此您必须首先解析该对象,然后从中取出该数组以正确解析。你错过了一个额外的步骤,我在上面的代码片段中添加了