我在dailymotion平台上有一个关于直播主播的应用程序。 Dailymotion 有一个 websdk(json 格式)。我不知道如何在android中使用json。我想知道如果 dailymotion live 打开或关闭,如何执行操作。我希望我们检查 json 所有 x 分钟。
JSON:https://api.dailymotion.com/video/x3p6d9r?fields=onair
请提出任何建议。
最佳答案
基本上,在 android 中,您必须手动或使用某些第三方库解析 JSON 响应。
例如如果您有如下 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"
}
]
}
然后你可以按如下方式解析上面的响应: 导入 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 或其他一些库来解析上述响应。
关于java - 每x分钟检查一次JSON数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39226456/