asp.net JSON.NET解析结果 [英] asp.net json.net parse results

查看:228
本文介绍了asp.net JSON.NET解析结果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我可不是熟悉JSON数据解析。到目前为止,这是从来就想出通过网络调查:
数据解析:
https://api.twitch.tv/kraken/streams/

I´m not familiar with JSON data parsing. So far, this is what I´ve come up to through web research: data to parse: https://api.twitch.tv/kraken/streams/

我正尝试使用JSON.NET/VB.NET框架,这样做的:

I´m trying to use the JSON.NET/VB.NET framework to do so:

Imports Newtonsoft.Json
Imports Newtonsoft.Json.Linq

'(inside a function)
Dim json As JObject = JObject.Parse("https://api.twitch.tv/kraken/streams/")
strResult As String = json.SelectToken("streams").SelectToken("game")

返回汇入作业我一个错误信息,我敢肯定我不具备的结构权。我如何才能让这项工作?事后,我倒是喜欢通过返回数组的结果循环。

It´s returning me an error message, and I´m sure I don´t have the structure right. How could I make this work? And afterwards, I´d like to loop through the results of the returning array.

谢谢,

推荐答案

这应该让你去(只是一个概念性的例子 - 控制台,而不是asp.net):

This should get you going (just a conceptual example - console, not asp.net):

Dim json As JObject = _
    JObject.Parse(New WebClient().DownloadString("https://api.twitch.tv/kraken/streams/"))

If json IsNot Nothing AndAlso json.HasValues Then

   If json.SelectTokens("streams") IsNot Nothing _
      AndAlso json.SelectTokens("streams").Children().Any() Then

      Dim games() As JToken = json.SelectTokens("streams").Children().ToArray()

      For Each child As JToken In games

          Console.WriteLine("game title: {0} game id: {1} for mature audience? {2}", _
                                      child.Item("game"), child.Item("_id"), child.Item("channel").Item("mature"))
          Console.WriteLine()
      Next

      Console.ReadLine()
   End If

End If

Hth以上....

Hth....

这篇关于asp.net JSON.NET解析结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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