数据格式为
{sid:737,tts:http://news.iciba.com/admin/tts/2013-12-11.mp3,content:I don't want us to be together because we have to,I want us to be together because we want to.,note:我不希望我们因为“不得不”而在一起,我希望我们是因为想在一起而在一起,Android 图文数据JSON解析,金山词霸每日一句API的调用
。,translation:感谢@程很多要秒虐数学 投稿。词霸小编,这句话来自《冰河世纪2》,是一个系列的动画电影,非常搞笑,你看过吗?,picture:http://cdn.iciba.com/news/word/2013-12-11.jpg,picture2:http://cdn.iciba.com/news/word/big_2013-12-11b.jpg,caption:词霸每日一句,dateline:2013-12-11,s_pv:8693,sp_pv:2090,tags:[{id:9,name:爱情},{id:14,name:电影经典}],fenxiang_img:http://cdn.iciba.com/web/news/longweibo/imag/2013-12-11.jpg}JSON字段解释
JSON 字段解释{'sid':'' #每日一句ID'tts': '' #音频地址'content':'' #英文内容'note': '' #中文内容'translation':'' #词霸小编'picture': '' #图片地址'picture2': '' #大图片地址'caption':'' #标题'dateline':'' #时间's_pv':'' #浏览数'sp_pv':'' #语音评测浏览数'tags':'' #相关标签'fenxiang_img':'' #合成图片,建议分享微博用的}最终实现的效果
具体实现,使用AsynTask异步访问网络:
class Load extends AsyncTask<string, string="">{ public String url = http://open.iciba.com/dsapi/; ProgressDialog pdlg; String jsonstr = ; JSONObject json = null; @Override protected String doInBackground(String... params) { // TODO Auto-generated method stub try{ DefaultHttpClient httpClient = new DefaultHttpClient(); HttpPost httppost = new HttpPost(url); HttpResponse httpResponse = httpClient.execute(httppost); HttpEntity httpEntity = httpResponse.getEntity(); InputStream is = httpEntity.getContent(); BufferedReader reader = new BufferedReader(new InputStreamReader(is, UTF-8)); StringBuilder sb = new StringBuilder(); String line = null; while ((line = reader.readLine()) != null) { sb.append(line + ); } is.close(); jsonstr = sb.toString(); json = new JSONObject(jsonstr.toString()); engstr = json.getString(content); chistr = json.getString(note); imagurl = json.getString(picture); timestr = json.getString(dateline); fromstr = json.getString(translation); JSONArray array = json.getJSONArray(tags); for(int i=0;i</p><p> 使用了一个图片处理的工具类,ImageLoader,主要用来通过url解析图片,处理图片的大小,以文件的形式缓存图片。</p>