Reputation: 3110
I'm working on my first Android Application and I'm having issue with using API and getting data using Json. This is the API link
API code :
jQuery(function($) {
$.getJSON('http://muslimsalat.com/london/daily.json?key=API_KEY&jsoncallback=?', function (times)
{
$('.prayerTimesExample')
.append('Today in '+times.title)
.append(' Fajr: '+times.items[0].fajr)
.append(' Dhuhr: '+times.items[0].dhuhr)
.append(' Asr: '+times.items[0].asr)
.append(' Maghrib: '+times.items[0].maghrib)
.append(' Isha: '+times.items[0].isha)
.append(' by MuslimSalat.com');
});
});
So I need your help how to call this API and get the result into string an explication or example. Thanks you
Upvotes: 0
Views: 415
Reputation: 1768
i've get the key for that api i.e. 5ad273b81ff66c6f3248604cfc728baa call simple api .... api call to get daily prayer
use code to fetch value...
try
{
HttpClient client=new DefaultHttpClient();
HttpGet request=new HttpGet("http://muslimsalat.com/daily.json?key=5ad273b81ff66c6f3248604cfc728baa");
HttpResponse response=client.execute(request);
HttpEntity entity=response.getEntity();
String json=EntityUtils.toString(entity);
JSONObject jsonObject=new JSONObject(json);
Toast.makeText(MainActivity.this, jsonObject.getString("title")+"\n"+jsonObject.getString("prayer_method_name"), 0).show();
entity.consumeContent();
}
catch(Exception e)
{
e.getStackTrace();
Toast.makeText(MainActivity.this, e.toString() , 0).show();
}
Upvotes: 1