0

你好伙计们这是我的代码我收到了这个错误方法 makeHttpRequest(String, String, List)

对于 JSONParser 类型未定义

如何处理这个问题请有人帮帮我,为什么 makeHttpRequest 没有为 JSONParser 定义

protected String doInBackground(String... args) {
        // Building Parameters
        List<NameValuePair> params = new ArrayList<NameValuePair>();
        // getting JSON string from URL
        JSONObject json = jParser.makeHttpRequest(url_all_products, "GET", params);

        // Check your log cat for JSON reponse
        Log.d("All Products: ", json.toString());

        try {
            // Checking for SUCCESS TAG
            int success = json.getInt(TAG_SUCCESS);

            if (success == 1) {
                // products found
                // Getting Array of Products
                products = json.getJSONArray(TAG_PRODUCTS);

                // looping through All Products
                for (int i = 0; i < products.length(); i++) {
                    JSONObject c = products.getJSONObject(i);

                    // Storing each json item in variable
                    String id = c.getString(TAG_PID);
                    String name = c.getString(TAG_NAME);

                    // creating new HashMap
                    HashMap<String, String> map = new HashMap<String, String>();

                    // adding each child node to HashMap key => value
                    map.put(TAG_PID, id);
                    map.put(TAG_NAME, name);

                    // adding HashList to ArrayList
                    productsList.add(map);
                }
            } else {
                // no products found
                // Launch Add New product Activity
                Intent i = new Intent(getApplicationContext(),
                        NewProductActivity.class);
                // Closing all previous activities
                i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
                startActivity(i);
            }
        } catch (JSONException e) {
            e.printStackTrace();
        }

        return null;
    }
4

1 回答 1

0

使用此代码:

DefaultHttpClient   httpclient = new DefaultHttpClient(new BasicHttpParams());
DefaultHttpClient defaultClient = new DefaultHttpClient();
                // Setup the get request
HttpGet httpGetRequest = new HttpGet("http://10.0.2.2:8080");
                try{
                    // Execute the request in the client
                    HttpResponse httpResponse = defaultClient.execute(httpGetRequest);
                    // Grab the response
                    BufferedReader reader = new BufferedReader(new InputStreamReader(httpResponse.getEntity().getContent(), "UTF-8"));
                    json = reader.readLine();                       
                    }catch(Exception e){
                        Log.d("Error",e.toString());
                    }
于 2013-08-15T12:56:20.863 回答