Java Android使用JSON错误:";分析数据org.json.JSONException:Value时出错;

Java Android使用JSON错误:";分析数据org.json.JSONException:Value时出错;,java,android,json,Java,Android,Json,我有一段代码,我在本地主机中使用它来显示一个listView,当我上传它时,我的listView中没有显示任何内容。这就是我所做的。通常我会将所有数据保存在数据库中,但屏幕是空的 private ListView listView; public static final String URL="http://gabes.comlu.com/Base_Controle/getAllEmp.php"; // static String TAG_JSON_ARRAY=""; privat

我有一段代码,我在本地主机中使用它来显示一个listView,当我上传它时,我的listView中没有显示任何内容。这就是我所做的。通常我会将所有数据保存在数据库中,但屏幕是空的

 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);
    }
私有ListView ListView;
公共静态最终字符串URL=”http://gabes.comlu.com/Base_Controle/getAllEmp.php";
//静态字符串TAG_JSON_ARRAY=“”;
私有字符串JSON_字符串;
静态JSONObject结果=null;
公共静态最终字符串标记_JSON_ARRAY=“result”;
私人雇员(){
JSONObject JSONObject=null;
ArrayList=新建ArrayList();
试一试{
jsonObject=新的jsonObject(JSON_字符串);
JSONArray result=jsonObject.getJSONArray(TAG_JSON_数组);

对于(int i=0;i您的JSON_数组常量没有值:

static String TAG_JSON_ARRAY="";

您正试图获得一个带有空标记的
JSONArray
,这就是为什么您会得到一个
异常

您可以使用库解析此json数据

}谢谢大家:) 我通过编辑以下内容解决了问题:

private String JSON_STRING;
static JSONObject result = null;
......
 try {
                JSONArray result = new JSONArray(json);
            for(int i = 0; i<result.length(); i++){
}
 protected void onPostExecute(String s) {
                super.onPostExecute(s);
                loading.dismiss();

                JSON_STRING = s;
                showEmployee(s);
            }
私有字符串JSON\u字符串;
静态JSONObject结果=null;
......
试一试{
JSONArray结果=新的JSONArray(json);

对于(int i=0;i放置您的logcat和json请发布您的json和stacktrace!您没有从web获取json?我检查了您的响应。我没有看到任何“结果”json数组。
public class test {

String nom;
String add;
String tele;


public String getNom() {
    return nom;
}

public void setNom(String nom) {
    this.nom = nom;
}

public String getAdd() {
    return add;
}

public void setAdd(String add) {
    this.add = add;
}

public String getTele() {
    return tele;
}

public void setTele(String tele) {
    this.tele = tele;
}
private String JSON_STRING;
static JSONObject result = null;
......
 try {
                JSONArray result = new JSONArray(json);
            for(int i = 0; i<result.length(); i++){
}
 protected void onPostExecute(String s) {
                super.onPostExecute(s);
                loading.dismiss();

                JSON_STRING = s;
                showEmployee(s);
            }