Android 列表视图未由json解析填充

Android 列表视图未由json解析填充,android,json,listview,Android,Json,Listview,我正在尝试使用JSONArray解析字符串。我在日志中得到警告: org.json.JSON.typeMismatch(JSON.java:107) org.json.JSONArray.<init>(JSONArray.java:91) org.json.JSONArray.<init>(JSONArray.java:103) org.json.json.typeMismatch(json.java:107) json.JSONArray(JSONArray.java

我正在尝试使用JSONArray解析字符串。我在日志中得到警告:

org.json.JSON.typeMismatch(JSON.java:107)
org.json.JSONArray.<init>(JSONArray.java:91)
org.json.JSONArray.<init>(JSONArray.java:103)
org.json.json.typeMismatch(json.java:107)
json.JSONArray(JSONArray.java:91)
json.JSONArray(JSONArray.java:103)
我的代码:

@Override
protected void onPostExecute(String result) {
super.onPostExecute(result);


mylist = new ArrayList<HashMap<String, String>>();
map = new HashMap<String, String>();
try {

    JSONArray arr = new JSONArray(result);

        for (int i = 0; i < arr.length(); i++) {

             JSONObject jObj = arr.getJSONObject(i);
            c_id = jObj.getString(CID);
            j_make = jObj.getString(MAKE);
            j_model = jObj.getString(MODEL);
            j_version = jObj.getString(VERSION);
            j_price = jObj.getString(PRICE);
            j_reg_plc = jObj.getString(PLACE_REG);

            data = "Make: " + j_make + "\nModel: " + j_model
                           + "\nVersion: " + j_version + "\nPrice: " + j_price
                   + "\nCity: " + j_reg_plc;

            map.put("car", data);
            mylist.add(map);

            }
        } catch (JSONException e) {
            e.printStackTrace();
        }

    list = (ListView) findViewById(R.id.listView1);

    String[] from = new String[] { "car" };
    int[] to = new int[] { R.id.text1 };
    ListAdapter adapter = new SimpleAdapter(view_cars.this, mylist, 
                          R.layout.text_adaptr, from, to);


}
@覆盖
受保护的void onPostExecute(字符串结果){
super.onPostExecute(结果);
mylist=新的ArrayList();
map=新的HashMap();
试一试{
JSONArray arr=新JSONArray(结果);
对于(int i=0;i
我对wats错误一无所知,因为相同的代码在不同的目的下工作

-----更新-----

我已经克服了这个警告。这是一个脚本错误。 但代码仍然不起作用

我收到一个json数组,例如-[{“car_id:“22”,“model:“model1”}]等等

我的全部代码

public class view_cars extends ListActivity {

public String s_id, ID, is, str;
String FILENAME = "http://animsinc.com/viewCars.php";

ListView list;
String data;

ArrayList<HashMap<String, String>> mylist;

HashMap<String, String> map;

static String j_id = null;
static Object j_make = null;
static String j_model = null;
static String j_version = null;
static String j_price = null;
static String j_reg_plc = null;

String CID = "car_id";
String MAKE = "make";
String MODEL = "model";
String VERSION = "version";
String PRICE = "expected_price";
String PLACE_REG = "registration_place";

@Override
protected void onCreate(Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    super.onCreate(savedInstanceState);
    setContentView(R.layout.view_prof);

    Bundle bundle = getIntent().getExtras();
    String stuff = bundle.getString("stuff");

    list = getListView();
    String[] values = new String[] { "Android", "iPhone", "WindowsMobile",
            "Blackberry", "WebOS", "Ubuntu", "Windows7", "Max OS X",
            "Linux", "OS/2" };

        ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
            android.R.layout.simple_list_item_1, values);
        setListAdapter(adapter);

    Toast.makeText(this, "try " + stuff, 1000).show();


    try {

        JSONArray jArray = new JSONArray(stuff.toString());

        for (int i = 0; i < jArray.length(); i++) {

            JSONObject jObject = jArray.getJSONObject(i);
            s_id = jObject.getString("seller_id");
            // s_id = jObject.getString(ID);
        }
    } catch (JSONException e) {
        e.printStackTrace();
    }
    Toast.makeText(this, "JSON: " + s_id, 1000).show();

    startDownload();

}


@Override
public void onBackPressed() {
    // TODO Auto-generated method stub
    super.onBackPressed();

    Intent CheckProfile = new Intent(this, MenuPg.class);
    startActivity(CheckProfile);

}

private void startDownload() {

    new AppTask().execute(FILENAME);
}

public class AppTask extends AsyncTask<String, Integer, String> {

    @Override
    protected void onPreExecute() {
        super.onPreExecute();

    }

    @Override
    protected void onPostExecute(String result) {
        super.onPostExecute(result);

         Toast.makeText(view_cars.this, ""+ result, 1000).show();
        // display(is);

        // void display(String res){

        str = result;

        mylist = new ArrayList<HashMap<String, String>>();
        map = new HashMap<String, String>();
        try {
            Toast.makeText(getApplicationContext(),"Inside Try", Toast.LENGTH_LONG).show();
            JSONArray jJArray = new JSONArray(str);

            for (int i = 0; i < jJArray.length(); i++) {



                JSONArray e = jJArray.getJSONArray(i);


                JSONObject jObject = jJArray.getJSONObject(i);
                j_id = jObject.getString(ID);

                j_make = jObject.getString(MAKE);

                j_model = jObject.getString(MODEL);

                j_version = jObject.getString(VERSION);
                j_price = jObject.getString(PRICE);
                j_reg_plc = jObject.getString(PLACE_REG);

                data = "Make: "+ j_make + "\nModel: " + j_model + "\nVersion: " 
                                                 + j_version  + "\nPrice: " + j_price
                        + "\nCity: " + j_reg_plc;

                Toast.makeText(getApplicationContext(),""+data, Toast.LENGTH_LONG).show();

                map.put("car", data);

                mylist.add(map);

            }
        } catch (JSONException e) {
            e.printStackTrace();
        }




    //  list = (ListView) findViewById(R.id.listView1);
        Toast.makeText(getApplicationContext(),""+mylist, Toast.LENGTH_LONG).show();
        String[] from = new String[] { "car"};
        int[] to = new int[] { R.id.text1 };
        ListAdapter adapt = new SimpleAdapter(view_cars.this, mylist,
                R.layout.text_adaptr, from, to);

        list.setAdapter(adapt);

        // Assign adapter to ListView list.setAdapter(adapter);




    }

    @Override
    protected void onProgressUpdate(Integer... values) {
        // TODO Auto-generated method stub
        super.onProgressUpdate(values);
    }

    @Override
    protected String doInBackground(String... params) {
        // String is = null;
        // str1 = et1.getText().toString();
        // str2 = et2.getText().toString();


        HttpClient httpclient = new DefaultHttpClient();
        HttpPost httppost = new HttpPost(FILENAME);
        try {
            List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(
                    1);
            nameValuePairs.add(new BasicNameValuePair("s_id", s_id));
            httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
            httpclient.execute(httppost);

            HttpResponse response = httpclient.execute(httppost);
            HttpEntity entity = response.getEntity();
            is = EntityUtils.toString(entity);

        } catch (ClientProtocolException e) {
            // TODO Auto-generated catch block
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        } catch (IOException e) {
            // TODO Auto-generated catch block
        }

        return is;
    }
}

}
公共类视图\u活动{
公共字符串s_id,id,is,str;
字符串文件名=”http://animsinc.com/viewCars.php";
列表视图列表;
字符串数据;
ArrayList mylist;
HashMap图;
静态字符串j_id=null;
静态对象j_make=null;
静态字符串j_model=null;
静态字符串j_version=null;
静态字符串j_price=null;
静态字符串j_reg_plc=null;
字符串CID=“车辆id”;
字符串MAKE=“MAKE”;
字符串MODEL=“MODEL”;
String VERSION=“VERSION”;
String PRICE=“预期价格”;
String PLACE_REG=“注册地点”;
@凌驾
创建时受保护的void(Bundle savedInstanceState){
//TODO自动生成的方法存根
super.onCreate(savedInstanceState);
setContentView(R.layout.view\u prof);
Bundle Bundle=getIntent().getExtras();
String stuff=bundle.getString(“stuff”);
list=getListView();
字符串[]值=新字符串[]{“Android”、“iPhone”、“WindowsMobile”,
“黑莓”、“WebOS”、“Ubuntu”、“Windows7”、“Max OS X”,
“Linux”、“OS/2”};
ArrayAdapter=新的ArrayAdapter(此,
android.R.layout.simple_list_item_1,值);
setListAdapter(适配器);
Toast.makeText(这个“try”+stuff,1000.show();
试一试{
JSONArray jArray=newjsonarray(stuff.toString());
for(int i=0;iJSONObject json = new JSONObject(result);