Visual Basic反序列化json url

时间:2019-03-07 17:26:17

标签: json vb.net serialization

im尝试使用json反序列化使用Visual Basic通过电影的ID获取imdb ID

dim rawresp as string = read.readtoend() rawresp = textbox3.text

它工作正常,但我不希望整个json都写在文本框中,我只希望将imdb_id写入到textbox3.text中

让我们说json的链接-> https://api.themoviedb.org/3/movie/550?api_key=315b4646c080bc576529769498ccc658

Private Sub Button12_Click(sender As Object, e As EventArgs) Handles Button12.Click
    Dim uristring As String = ("https://api.themoviedb.org/3/movie/" + TextBox6.Text + "?api_key=315b4646c080bc576529769498ccc658")
    Dim uri As New Uri(uristring)
    Dim request As HttpWebRequest = HttpWebRequest.Create(uri)
    request.Method = "get"
    Dim response As HttpWebResponse = request.GetResponse()
    Dim read = New StreamReader(response.GetResponseStream)
    Dim rawresp As String = read.ReadToEnd()
    Dim dict As Object = New JavaScriptSerializer().Deserialize(Of List(Of Object))(rawresp)
    For Each item As Object In dict
        TextBox3.Text = item("imdb_id").ToString()
    Next
End Sub

1 个答案:

答案 0 :(得分:0)

尝试一下,希望对您有所帮助

Dim jsonResulttodict = JsonConvert.DeserializeObject(Of Dictionary(Of String, Object))(rawresp)
Dim imdb_ID = jsonResulttodict.item ("imdb_id")