The JSONParser class is lower down on the tutorial it looks like this...

public class JSONParser {

    static InputStream is = null;
    static JSONObject jObj = null;
    static String json = "";

    // constructor
    public JSONParser() {

    }

    // function get json from url
    // by making HTTP POST or GET method
    public JSONObject makeHttpRequest(String url, String method,
            List<NameValuePair> params) {

        // Making HTTP request
        try {

            // check for request method
            if(method == "POST"){
                // request method is POST
                // defaultHttpClient
                DefaultHttpClient httpClient = new DefaultHttpClient();
                HttpPost httpPost = new HttpPost(url);
                httpPost.setEntity(new UrlEncodedFormEntity(params));

                HttpResponse httpResponse = httpClient.execute(httpPost);
                HttpEntity httpEntity = httpResponse.getEntity();
                is = httpEntity.getContent();

            }else if(method == "GET"){
                // request method is GET
                DefaultHttpClient httpClient = new DefaultHttpClient();
                String paramString = URLEncodedUtils.format(params, "utf-8");
                url += "?" + paramString;
                HttpGet httpGet = new HttpGet(url);

                HttpResponse httpResponse = httpClient.execute(httpGet);
                HttpEntity httpEntity = httpResponse.getEntity();
                is = httpEntity.getContent();
            }           

        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        } catch (ClientProtocolException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }

        try {
            BufferedReader reader = new BufferedReader(new InputStreamReader(
                    is, "iso-8859-1"), 8);
            StringBuilder sb = new StringBuilder();
            String line = null;
            while ((line = reader.readLine()) != null) {
                sb.append(line + "\n");
            }
            is.close();
            json = sb.toString();
        } catch (Exception e) {
            Log.e("Buffer Error", "Error converting result " + e.toString());
        }

        // try parse the string to a JSON object
        try {
            jObj = new JSONObject(json);
        } catch (JSONException e) {
            Log.e("JSON Parser", "Error parsing data " + e.toString());
        }

        // return JSON String
        return jObj;

    }
}

I would consider looking at the jackson library tho http://jackson.codehaus.org/

Answer from user1791586 on Stack Overflow
Top answer
1 of 1
11

The JSONParser class is lower down on the tutorial it looks like this...

public class JSONParser {

    static InputStream is = null;
    static JSONObject jObj = null;
    static String json = "";

    // constructor
    public JSONParser() {

    }

    // function get json from url
    // by making HTTP POST or GET method
    public JSONObject makeHttpRequest(String url, String method,
            List<NameValuePair> params) {

        // Making HTTP request
        try {

            // check for request method
            if(method == "POST"){
                // request method is POST
                // defaultHttpClient
                DefaultHttpClient httpClient = new DefaultHttpClient();
                HttpPost httpPost = new HttpPost(url);
                httpPost.setEntity(new UrlEncodedFormEntity(params));

                HttpResponse httpResponse = httpClient.execute(httpPost);
                HttpEntity httpEntity = httpResponse.getEntity();
                is = httpEntity.getContent();

            }else if(method == "GET"){
                // request method is GET
                DefaultHttpClient httpClient = new DefaultHttpClient();
                String paramString = URLEncodedUtils.format(params, "utf-8");
                url += "?" + paramString;
                HttpGet httpGet = new HttpGet(url);

                HttpResponse httpResponse = httpClient.execute(httpGet);
                HttpEntity httpEntity = httpResponse.getEntity();
                is = httpEntity.getContent();
            }           

        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        } catch (ClientProtocolException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }

        try {
            BufferedReader reader = new BufferedReader(new InputStreamReader(
                    is, "iso-8859-1"), 8);
            StringBuilder sb = new StringBuilder();
            String line = null;
            while ((line = reader.readLine()) != null) {
                sb.append(line + "\n");
            }
            is.close();
            json = sb.toString();
        } catch (Exception e) {
            Log.e("Buffer Error", "Error converting result " + e.toString());
        }

        // try parse the string to a JSON object
        try {
            jObj = new JSONObject(json);
        } catch (JSONException e) {
            Log.e("JSON Parser", "Error parsing data " + e.toString());
        }

        // return JSON String
        return jObj;

    }
}

I would consider looking at the jackson library tho http://jackson.codehaus.org/

🌐
CopyProgramming
copyprogramming.com › howto › constructor-jsonparser-in-class-jsonparser-cannot-be-applied-to-given-types-error-occured
JSONParser Cannot Be Resolved to a Type: Complete Solution Guide for 2026 - Jsonparser cannot be resolved to a type
October 19, 2025 - The "JSONParser cannot be resolved to a type" error is one of the most common obstacles Java developers encounter when working with JSON data. This error occurs when your IDE or compiler cannot find the JSONParser class because the necessary library dependency is missing from your project or ...
🌐
Google Groups
groups.google.com › d › topic › jbpm-usage › B62P8Wt8GMo
Import in JBPM Script Task
April 27, 2015 - Process Compilation error JSONParser cannot be resolved to a type JSONParser cannot be resolved to a type JSONObject cannot be resolved to a type JSONObject cannot be resolved to a type
🌐
YouTube
youtube.com › hey delphi
Android : JSONParser cannot be resolved to a type - YouTube
Android : JSONParser cannot be resolved to a typeTo Access My Live Chat Page, On Google, Search for "hows tech developer connect"Here's a secret feature that...
Published   May 26, 2023
Views   5
Find elsewhere
🌐
Adobe Experience League
experienceleaguecommunities.adobe.com › t5 › adobe-experience-manager › how-to-use-gson-library › m-p › 205951
Solved: How to use Gson library - Adobe Experience League Community - 205951
October 16, 2015 - Hi, I'm trying to import and use Google Gson library in my servlet but when I try to compile the servlet I get these errors com.google.gson.JsonElement cannot be resolved to a type com.google.gson.JsonParser cannot be resolved to a type com.google.gson.JsonObject cannot be resolved to a type The Gso...
🌐
Talend
community.talend.com › s › feed › 0D53p00007vCk2bCAC
import org.json.
October 9, 2015 - Loading · ×Sorry to interrupt · Refresh
🌐
Talend
community.talend.com › s › question › 0D55b000071oGDFCA2 › jsonobject-cannot-be-resolved-to-a-type
JSONObject cannot be resolved to a type
March 11, 2022 - 20260328T202526.634+0530 1171 User: 20260328T202526.634+0530 1172 Load 20260328T202526.634+0530 1173 userDirectory & '\' & userId AS UserId, 20260328T202526.634+0530 1174 [name] AS [User Name], 20260328T202526.634+0530 1175 userDirectory as [User Directory] 20260328T202526.634+0530 1177 SQL SELECT 20260328T202526.634+0530 1178 "userId", 20260328T202526.634+0530 1179 "userDirectory", 20260328T202526.634+0530 1180 "name" 20260328T202526.634+0530 1181 FROM JSON (wrap on) "root" 20260328T202526.847+0530 3 fields found: UserId, User Name, User Directory, 20260328T202526.850+0530 Error: HTTP protocol error 401 (Unauthorized): 20260328T202526.850+0530 20260328T202526.850+0530 Requested resource requires authentication. 20260328T202526.851+0530 Execution Failed 20260328T202526.856+0530 Execution finished. What could be the issue and how to resolve it.
🌐
The Coding Forums
thecodingforums.com › archive › archive › java
JSONArray cannot be resolved to a type | Java | Coding Forums
November 18, 2008 - Hi everybody, I'm trying a MapGuide JSP example, on Tomcat, with which I get this compiler error: org.apache.jasper.JasperException: Unable to compile class for JSP: An error occurred at line: 50 in the jsp file: /javaviewersample/query/ classes/query.jsp JSONArray cannot be resolved to a type 47: 48: public String getNumOp() 49: { 50: JSONArray jsonArray = new JSONArray(); 51: for(int i=0;i<6;i++) 52: { 53: jsonArray.put(numOperators); How come?
🌐
CopyProgramming
copyprogramming.com › howto › jsonproperty-cannot-be-resolved-to-a-type
Java: Unresolved Type Error for Jsonproperty
May 27, 2023 - Cannot Deserialise Json to Type,Unable to find, The lack of a true parameterless constructor for this type is what causes the Newtonsoft.Json: Unable to find a constructor to use for type Microsoft.Research.SEAL.Ciphertext. exception to be thrown.
🌐
Amazonaws
fevapo5jgge9zyfq.s3.amazonaws.com › method-cannot-be-resolved-to-a-type.html
Method Cannot Be Resolved To A Type - Matthew Carrasco blog
July 19, 2021 - Method Cannot Be Resolved To A ... eclipse gives me the jsonparser cannot be resolved to a type. The solution is to use e as the value for t....
🌐
Try2explore
try2explore.com › questions › 12351195
java - Jsonparser cannot resolve to type
But Eclipse gives me the JSONParser cannot be resolved to a type.