我正在开发一个应用程序,我在其中解析JSON
数据并在列表视图中修复结果。作为JSON
回应,我得到以下回应:
{
"searchdata": {
"webresult": [
{
"title": "<b>Android</b>",
"desc": "Discover a new flavor of Jelly Bean <b>Android</b> 4.2 introduces a completely new camera experience, a new form of typing that helps you power ...",
"link": "http://www.android.com/"
},
{
"title": "<b>Android</b> (operating system) - Wikipedia, the free encyclopedia",
"desc": "<b>Android</b> is a Linux -based operating system designed primarily for touchscreen mobile devices such as smartphones and tablet computers. Initially developed by <b>Android</b> ...",
"link": "http://en.wikipedia.org/wiki/Android_(mobile_phone_platform)"
}
]
}
}
如title
您所见,Android标签即将到来。我想让它变得大胆。
这是我为在列表视图中修复这些响应所做的工作。
try {
HttpClient hClient = new DefaultHttpClient();
HttpGet hGet = new HttpGet("MY API");
ResponseHandler<String> rHandler = new BasicResponseHandler();
data = hClient.execute(hGet, rHandler);
JSONObject rootObj = new JSONObject(data);
JSONObject jSearchData = rootObj.getJSONObject("searchdata");
JSONArray jsonArray = jSearchData.getJSONArray("webresult");
for (int i = 0; i < jsonArray.length(); i++) {
JSONObject objJson = jsonArray.getJSONObject(i);
String title = objJson.getString("title");
String desc = objJson.getString("desc");
String link = objJson.getString("link");
HashMap<String, String> map = new HashMap<String, String>();
map.put("title", title);
map.put("description", desc);
map.put("link", link);
searchList.add(map);
}
} catch (Exception e) {
System.out.println("Exception: " + e);
}
通过上面的代码,我得到了响应并将它们存储到Hashmap
. 之后,我使用自定义布局来显示内容。以下代码可帮助我在布局中固定值。
ListAdapter adapter = new SimpleAdapter(getApplicationContext(),
searchList, R.layout.list_row, new String[] { "title","description", "link" }, new int[] { R.id.title,R.id.desc, R.id.url });
setListAdapter(adapter);
这就是一切顺利时的样子。
如您所见,html
标签即将到来。请任何人建议如何使html
粗体标签内的文本变为粗体?
任何帮助将不胜感激。