【问题标题】:How to parse JSON sections using json-simple in Java?如何在 Java 中使用 json-simple 解析 JSON 部分?
【发布时间】:2015-11-15 12:48:25
【问题描述】:

我目前正在使用 Twitch API 来获取有关直播的信息。但是,我似乎无法在流部分下为观众等获取数据。我使用 json-simple 作为 maven 依赖项。

{
  "_links": {
"channel": "https://api.twitch.tv/kraken/channels/test_channel",
"self": "https://api.twitch.tv/kraken/streams/test_channel"},
"stream": {
"game": "StarCraft II: Heart of the Swarm",
"viewers": 2123,
"average_fps": 29.9880749574,
"delay": 0,
"video_height": 720,
"is_playlist": false,
"created_at": "2015-02-12T04:42:31Z",
"_id": 4989654544,

【问题讨论】:

    标签: java json maven json-simple


    【解决方案1】:

    以下是获取viewers 数据的示例:

    JSONParser parser = new JSONParser();
    // handle exceptions for this line
    JSONObject jsonObject = (JSONObject) parser.parse(new FileReader(new File("data.json")));
    JSONObject streamObject = (JSONObject) jsonObject.get("stream");
    long viewers = (Long) streamObject.get("viewers");
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-04-01
      • 2015-11-11
      • 1970-01-01
      • 1970-01-01
      • 2020-01-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多