I am try to develop a sample application for YouTube to play video on my android device directly from YouTube. In this respect I have developed some code to parse JSON, but I haven't succeeded so far. Please help me, how to parse Youtube JSON? Here is my code.
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
getVideoJSON ();
}
public JSONObject getVideoJSON ()
{
final String URL = "https://gdata.youtube.com/feeds/api/users/Football/uploads?v=2&alt=json";
try
{
StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
StrictMode.setThreadPolicy(policy);
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost(URL);
HttpResponse response = httpclient.execute(httppost);
HttpEntity entity = response.getEntity();
String data = EntityUtils.toString(entity);
JSONArray VideoData = new JSONArray(data);
JSONObject video = VideoData.getJSONObject(0);
Log.e("URL", "Successfully parse");
return video;
}
catch(Exception e)
{
Log.e("URL", "Failed");
e.printStackTrace();
}
return null;
}