如何解析在vb.net JSON阵列? [英] How to parse json array in vb.net?

查看:241
本文介绍了如何解析在vb.net JSON阵列?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在学习有关的 JSON 我要解析JSON阵列,通过只得到一个值 VB.Net 。我发现这个问题的答案,但中的我好像没得到什么我一直在寻找的。根据提问,他有这个

I am learning about JSON and I want to parse json array and get only one value using VB.Net. I found this QUESTION with answers but I didn't seem to get what I was looking for. According the the questioner, he has this

"links":[
  {
    "rel":"next",
    "href":"www.google.com"
  }
]

和我们可以用它来解析JSON阵列

and we can use this to parse json array

   links(1).Item("rel")

或本

links(1)("rel")

如果我唯一有此?

What if I only have this?

[{
    "rel":"next",
    "href":"www.google.com"
}]

我应该怎样code是无字的链接?我明白的链接的是表名,不是吗?我试了很多可能性的给我更多的错误。我倒是AP preciate多,如果任何人都可以帮助我。

How should I code it without the word links? I understand that links is the table name, isn't it? I tried so many possibilities which give me more errors. I'd appreciate much if anyone can help me out.

P.S。这不是重复,以<一个href=\"http://stackoverflow.com/questions/18076744/how-to-parse-json-list-in-vb-net-newtonsoft\">this因为我不打算将信息添加到一个DataGridView。我想这里是解析一个字段。只得到一个结果,而不是整个列表。

P.S. This not a duplicate to this because I am not going to add the information to a DataGridView. What I want here is to parse a field. Get only one result and not the entire list.

推荐答案

发现这个可以解析 JSON 此提供的安装。

found this that can parse json providing this library is installed.

        Dim token As JToken
        Dim rel
        Dim href
        For Each value As Object In result
            token = JObject.Parse(value.ToString())
            rel = token.SelectToken("rel")
            href = token.SelectToken("href")

            Console.WriteLine("{0} {1}", rel, href)
        Next value

规定本code是present

providing that this code is present

' Create a request for the URL. 
        Dim request As WebRequest = WebRequest.Create("http://")

        ' If required by the server, set the credentials.
        request.Credentials = CredentialCache.DefaultCredentials
        ' Get the response.
        Dim response As WebResponse = request.GetResponse()
        ' Display the status.
        Console.WriteLine(CType(response, HttpWebResponse).StatusDescription)
        ' Get the stream containing content returned by the server.
        Dim dataStream As Stream = response.GetResponseStream()
        ' Open the stream using a StreamReader for easy access.
        Dim reader As New StreamReader(dataStream)
        ' Read the content.
        Dim responseFromServer As String = reader.ReadToEnd()
        'Dim responseFromServer As String = reader.ReadToEnd()
        Console.WriteLine(responseFromServer)
        Dim result = JsonConvert.DeserializeObject(Of ArrayList)(responseFromServer)

和这个code中的的

and this code at the bottom

        Console.ReadKey()
        ' Clean up the streams and the response.
        reader.Close()
        response.Close()

与进口...

        Imports System
        Imports System.IO
        Imports System.Net
        Imports System.Text
        Imports Newtonsoft.Json
        Imports Newtonsoft.Json.Linq

在这里找到和 <一href=\"https://adevelopersnotes.word$p$pss.com/2013/11/10/parsing-json-to-key-value-pairs-with-json-net/\"相对=nofollow>这是在C#形式的code,我发现...仅供参考。

found it here and this is a code in c# form that i found... for reference only.

这篇关于如何解析在vb.net JSON阵列?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆