我有這段代碼,我用它在本地主機上顯示一個listView,當我上傳它時,沒有任何顯示在我的ListView中。所以這就是我所做的。通常我會將所有數據保存在我的數據庫中,但屏幕是空的。Android使用JSON錯誤:「解析數據時出錯org.json.JSONException:值」
private ListView listView;
public static final String URL="http://gabes.comlu.com/Base_Controle/getAllEmp.php";
// static String TAG_JSON_ARRAY="";
private String JSON_STRING;
static JSONObject result = null;
public static final String TAG_JSON_ARRAY = "result";
private void showEmployee(){
JSONObject jsonObject = null;
ArrayList<HashMap<String,String>> list = new ArrayList<HashMap<String, String>>();
try {
jsonObject = new JSONObject(JSON_STRING);
JSONArray result = jsonObject.getJSONArray(TAG_JSON_ARRAY);
for(int i = 0; i<result.length(); i++){
JSONObject jo = result.getJSONObject(i);
String nom1 = jo.getString("nom");
String tele1 = jo.getString("tele");
String grade1 = jo.getString("grade");
String image1 = jo.getString("image");
String site1 = jo.getString("site");
String email1 = jo.getString("email");
HashMap<String,String> employees = new HashMap<>();
// employees.put("Type",type);
employees.put("log",nom1);
employees.put("a",tele1);
employees.put("pre",grade1);
employees.put("d",image1);
employees.put("c",site1);
employees.put("b", email1);
list.add(employees);
}
} catch (JSONException e) {
e.printStackTrace();
Log.e("JSON Parser", "Error parsing data " + e.toString());
}
ListAdapter adapter = new SimpleAdapter(
getActivity(), list, R.layout.list_item1,
new String[]{"log","pre","a","b","c","d"},
new int[]{R.id.id, R.id.name,R.id.a});
listView.setAdapter(adapter);
}
發表您的logcat和json – Mohit
請張貼你的json和你的stacktrace! –
你沒有從網絡上獲得JSON? –