繁体   English   中英

Android和Json获取数据

[英]Android and Json Get Data

我正在开发我的第一个Android应用程序,但是在使用API​​和使用Json获取数据时遇到了问题。 这是API 链接

API代码:

    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');
     });
});

因此,我需要您的帮助,如何调用此API并将结果转换为字符串,作为示例或示例。 谢谢

我已经获得该API的密钥,即5ad273b81ff66c6f3248604cfc728baa调用简单api .... api调用以获得每日祈祷

使用代码获取价值...

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();
            }

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM