johnsnow85 johnsnow85 - 3 months ago 10
Android Question

Check a JSON data every x minutes

I have an application about live streamer on dailymotion platform. Dailymotion have a websdk (in json). I didn't know how use json in android. I want to know how do an action if dailymotion live is on or off. And i want we check json all x minutes.

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

Any suggestions please.

Answer

Basically, In android u will have to parse JSON response either manually or using some Third party library.

e.g. if you have JSON response like follows:

{
   "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"
         }
    ]
}

Then you can parse the above response as follows: 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");
    ...... 
} 

You can also parse the above response using GSON library or some other library.

Comments