我正在使用返回JSON作爲響應的Web服務。我想解析響應並創建一個對象列表。我不知道如何在UI中顯示解析的數據。用戶可以從列表中選擇一個項目(即迪拜購物中心或迪拜媒體城市或迪拜節日)。如何在android中解析JSON並在ListVIew中顯示數據列表?
public class MyLocation extends MapActivity {
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.location);
initButtons();
initMapView();
initMyLocation();
jObject=getJSONFile("http://loyaltier.com/app/mobile/code/places/Maps.php");
}
private JSONObject getJSONFile(String URL) {
JSONObject jObject=null;
HttpGet httpGet=new HttpGet(URL); //http://loyaltier.com/app/mobile/code/places/Maps.php
HttpClient httpClient=new DefaultHttpClient();
HttpResponse httpResponse;
StringBuilder stringBuilder=new StringBuilder();
try{
httpResponse=httpClient.execute(httpGet);
HttpEntity httpEntity=httpResponse.getEntity();
InputStream inputStream=httpEntity.getContent();
int c;
while((c=inputStream.read())!=-1){
stringBuilder.append((char)c);
}
}catch(Exception e){
e.printStackTrace();
}
try{
jObject=new JSONObject(stringBuilder.toString());
}catch(JSONException e){
Log.e("Log_tags ", "Error parsing data "+e.toString());
}
return jObject;
}
}
無法訪問JSON元素,如分支ID和等通過JSON?我只使用JACKSON?謝謝 – user1797707
請發佈傑克遜解析代碼和java bean類... –