我想在列表视图中显式地显示json响应。我如何获得在列表视图中显示json响应
DistrictName,块名称,集群名称,VillageSchools
这里是我的代码:
{
DistrictId: 1,
DistrictName: "mys",
BlockSchools: [
{
BlockId: 1,
BlockName: "Adoni",
ClusterSchools: [
{
ClusterId: 1,
ClusterName: "Giddalur",
VillageSchools: [
{
VillageId: 1,
VillageName: "Kurly",
VillageSchools: [
{
SchoolId: 37,
SchoolName: "NORTH CHANGOUBUNG PRIMARY SCHOOL"
}
]
}
]
}
],
VillageSchools: [
{
VillageId: 1,
VillageName: "Kurly",
VillageSchools: [
{
SchoolId: 37,
SchoolName: "NORTH CHANGOUBUNG PRIMARY SCHOOL"
}
]
}
]
}
]
},
代码:
private class JSONParse
extends AsyncTask<String, String, ArrayList<HashMap<String, String>>> {
private ProgressDialog pDialog;
@Override
protected void onPreExecute() {
super.onPreExecute();
pDialog = new ProgressDialog(JsonActivity.this);
pDialog.setMessage("Getting Data ...");
pDialog.setIndeterminate(false);
pDialog.setCancelable(true);
pDialog.show();
}
protected ArrayList<HashMap<String, String>> doInBackground(String... args) {
ArrayList<HashMap<String, String>> contactList = new ArrayList<HashMap<String,String>>();
JSONParser jParser = new JSONParser();
// Getting JSON from URL
JSONObject json = jParser.getJSONFromUrl(url);
try {
String DistrictName = json.getString("DistrictName");
System.out.println("DistrictName: "+DistrictName);
// tmp hashmap for single contact
/* HashMap<String, String> contact = new HashMap<String, String>();
contact.put(TAG_NAME, DistrictName);
// adding contact to contact list
contactList.add(contact);*/
} catch (JSONException e) {
e.printStackTrace();
}
return contactList;
}
@Override
protected void onPostExecute(ArrayList<HashMap<String, String>> result) {
super.onPostExecute(result);
// Dismiss the progress dialog
if (pDialog.isShowing()) pDialog.dismiss();
ListAdapter adapter = new SimpleAdapter(JsonActivity.this, result, R.layout.list_item, new String[] { TAG_NAME, TAG_EMAIL, TAG_PHONE_MOBILE }, new int[]
{ R.id.textView1 });
lv.setAdapter(adapter);
}
}
}
你确定它是一个有效的JSON – Raghunandan
请问你目前的尝试失败了呢? –
http://119.82.102.118/eManipurSSA/Responses/Test.txt这个网址我想检索服务器的响应,我怎么能这样做 – user3114723