每x分钟检查一次JSON数据

时间:2016-08-30 11:35:50

标签: java android json

我在dailymotion平台上有关于直播的应用程序。 Dailymotion有一个websdk(在json中)。我不知道如何在android中使用json。我想知道如果日常运动是开启还是关闭的操作。我希望我们在x分钟内检查json。

JSON:https://api.dailymotion.com/video/x3p6d9r?fields=onair

请提出任何建议。

1 个答案:

答案 0 :(得分:1)

基本上,在android中你必须手动或使用某些第三方库来解析JSON响应。

e.g。如果你有如下的JSON响应:

{
   "pageInfo": {
         "pageName": "abc",
         "pagePic": "http://example.com/content.jpg"
    }
    "posts": [
         {
              "post_id": "123456789012_123456789012",
              "actor_id": "1234567890",
              "picOfPersonWhoPosted": "http://example.com/photo.jpg",
              "nameOfPersonWhoPosted": "Jane Doe",
              "message": "Sounds cool. Can't wait to see it!",
              "likesCount": "2",
              "comments": [],
              "timeOfPost": "1234567890"
         }
    ]
}

然后您可以解析上面的响应,如下所示: import org.json。*;

JSONObject obj = new JSONObject(" .... ");
String pageName = obj.getJSONObject("pageInfo").getString("pageName");

JSONArray arr = obj.getJSONArray("posts");
for (int i = 0; i < arr.length(); i++)
{ 
    String post_id = arr.getJSONObject(i).getString("post_id");
    ...... 
} 

您还可以使用GSON library或其他一些库解析上述回复。