这是我的 json 输出示例:
{"podcast":[{"link":"rtsp:\\live.xxx.ro:554\vod\_definst_\mp4:05\rfm_00.mp4","name":"Recording 1"}
为了解析 json 代码,我使用这个:
private static final String TAG_LINK = "link";
private static final String TAG_NAME = "name";
try {
int success = json.getInt(TAG_SUCCESS);
if (success == 1) {
products = json.getJSONArray(TAG_PRODUCTS);
for (int i = 0; i < products.length(); i++) {
JSONObject c = products.getJSONObject(i);
String link = c.getString(TAG_LINK);
String name = c.getString(TAG_NAME);
HashMap<String, String> map = new HashMap<String, String>();
map.put(TAG_LINK, link);
map.put(TAG_NAME, name);
productsList.add(map);
}
} else {
}
} catch (JSONException e) {
e.printStackTrace();
}
return null;
}
protected void onPostExecute(String file_url) {
pDialog.dismiss();
runOnUiThread(new Runnable() {
public void run() {
ListAdapter adapter = new SimpleAdapter(
PodCast.this, productsList,
R.layout.list_item, new String[] {
TAG_NAME, TAG_LINK },
new int[] { R.id.link, R.id.name });
setListAdapter(adapter);
}
});
对于布局,这是链接视图的代码:
<TextView
android:id="@+id/name"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:paddingTop="6dip"
android:paddingLeft="6dip"
android:paddingBottom="6dip"
android:textSize="17dip"
android:autoLink="web"
android:textColor="#fff"
android:textColorLink="#fff"
android:textStyle="bold"/>
一切正常...但在链接视图中,我得到了整个链接 rtsp://live.xxx.ro...等,我想成为这样的东西: <a href="rtsp://...">NAME </a>
所以我会有名字,当我点击它时打开指定的链接。各位大佬能帮我看看怎么弄吗?