title: parsing json data in API url using jsonparser
body: <p>I have a <code>JSON</code> data in this <code>URL</code> : <a href="http://api.pemiluapi.org/calonpresiden/api/caleg/jk?apiKey=56513c05217f73e6be82d5542368ae4f" rel="nofollow">http://api.pemiluapi.org/calonpresiden/api/caleg/jk?apiKey=56513c05217f73e6be82d5542368ae4f</a></p>
  
  <p>when I try parsing using this jsonparser code :  </p>
  
  <pre><code>    package percobaan;
  
  import java.io.BufferedReader;
  import java.io.IOException;
  import java.io.InputStream;
  import java.io.InputStreamReader;
  import java.io.UnsupportedEncodingException;
  import java.util.List;
  
  import org.apache.http.HttpEntity;
  import org.apache.http.HttpResponse;
  import org.apache.http.NameValuePair;
  import org.apache.http.client.ClientProtocolException;
  import org.apache.http.client.entity.UrlEncodedFormEntity;
  import org.apache.http.client.methods.HttpGet;
  import org.apache.http.client.methods.HttpPost;
  import org.apache.http.client.utils.URLEncodedUtils;
  import org.apache.http.impl.client.DefaultHttpClient;
  import org.json.JSONException;
  import org.json.JSONObject;
  
  public class JSONParser {
  
      static InputStream is = null;
      static JSONObject jObj = null;
      static String json = "";
  
      // constructor
      public JSONParser() {
  
      }
  
      public String makeHttpRequest(String url, String method) {
          return this.makeHttpRequest(url, method, null);
      }
  
      public JSONObject getJSONFromUrl(String url, List&lt;NameValuePair&gt; params) {
          // Making HTTP request
          try {
              // 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();
  
          } 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 sBuilder = new StringBuilder();
              String line = null;
              while ((line = reader.readLine()) != null) {
                  sBuilder.append(line + "\n");
              }
              is.close();
              json = sBuilder.toString();
          } catch (Exception exception) {
              exception.printStackTrace();
          }
  
          // try parse the string to a JSON object
          try {
              jObj = new JSONObject(json);
          } catch (JSONException e) {
  
          }
  
          // return JSON String
          return jObj;
  
      }
  
      // function get json from url
      // by making HTTP POST or GET mehtod
      public String makeHttpRequest(String url, String method,
              List&lt;NameValuePair&gt; params) {
  
          // Making HTTP request
          try {
              DefaultHttpClient httpClient = new DefaultHttpClient();
              // check for request method
              if (method == "POST") {
                  HttpPost httpPost = new HttpPost(url);
                  if (params != null) {
                      httpPost.setEntity(new UrlEncodedFormEntity(params));
                  }
                  HttpResponse httpResponse = httpClient.execute(httpPost);
                  HttpEntity httpEntity = httpResponse.getEntity();
                  is = httpEntity.getContent();
              } else if (method == "GET") {
                  if (params != null) {
                      String paramString = URLEncodedUtils
                              .format(params, "utf-8");
                      url += "?" + paramString;
                  }
                  HttpGet httpGet = new HttpGet(url);
                  // DefaultHttpClient httpClient = new
                  // DefaultHttpClient(httpParameters);
  
                  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) {
  
          }
  
          // return JSON String
          return json;
  
      }
  }
  </code></pre>
  
  <p>why the output just says :  </p>
  
  <pre><code>{"data":[]}  
  </code></pre>
  
  <p>this is my code :  </p>
  
  <pre><code>package percobaan;
  
  import java.util.ArrayList;
  import java.util.HashMap;
  import java.util.List;
  import org.apache.http.NameValuePair;
  import org.json.JSONArray;
  import org.json.JSONException;
  import org.json.JSONObject;
  
  /**
   *
   * @author nafian
   */
  public class Coba {
  
      public static void main(String[] args) {
          ArrayList&lt;HashMap&lt;String, String&gt;&gt; daftar_d = new ArrayList&lt;HashMap&lt;String, String&gt;&gt;();
          JSONParser jsonParser = new JSONParser();
          String link_url = "http://api.pemiluapi.org/calonpresiden/api/caleg/jk?apiKey=56513c05217f73e6be82d5542368ae4f";
          List&lt;NameValuePair&gt; params = new ArrayList&lt;NameValuePair&gt;();
          String parsing = jsonParser.makeHttpRequest(link_url, "POST",
                  params);
  
          System.out.print(parsing);
  //        try {
  //            JSONObject json = new JSONObject(parsing).getJSONObject("data").getJSONObject("results");
  //            JSONArray caleg = json.getJSONArray("caleg");
  //
  //            for (int i = 0; i &lt; caleg.length(); i++) {
  //                HashMap&lt;String, String&gt; map = new HashMap&lt;String, String&gt;();
  //                JSONObject ar = caleg.getJSONObject(i);
  //                String nama = ar.getString("nama");
  //                String calon = ar.getString("role");
  //
  //                JSONArray riwayat = ar.getJSONArray("riwayat_pendidikan");
  //                for (int j = 0; j &lt; riwayat.length(); j++) {
  //                    JSONObject ringkasan = riwayat.getJSONObject(j);
  //                    String ringkasan_p = ringkasan.getString("ringkasan");
  //                    map.put("pendidikan_r", ringkasan_p);
  //                }
  //
  //                map.put("nama", nama);
  //                map.put("calon", calon);
  //                daftar_d.add(map);
  //
  //            }
  //        } catch (JSONException ex) {
  //            ex.printStackTrace();
  //        }
  //        for (int i = 0; i &lt; daftar_d.size(); i++) {
  //
  //            System.out.println(daftar_d.get(i).get("pendidikan_r").toString());
  //        }
  
      }
  }
  </code></pre>
  
  <p>Am I missing something?</p>