title: JSON Android ListView
body: <p>I build this webservice on netbeans,</p>
  
  <pre><code>package in.figures.on.mobile;
  
  import db.koneksi.dbKoneksi;
  import java.sql.Statement;
  import java.sql.ResultSet;
  import java.util.ArrayList;
  import java.util.List;
  import java.util.Properties;
  import javax.jws.WebMethod;
  import javax.jws.WebParam;
  import javax.jws.WebService;
  import org.json.simple.JSONValue;
  
  /**
   *
   * @author Setyadi
   */
  @WebService()
  public class AksesData {
  
      /**
       * Web service operation
       */
      @WebMethod(operationName = "Kategori")
      public String Kategori() {
          //TODO write your implementation code here:
  
          dbKoneksi con = new dbKoneksi();
          Statement statement;
          Properties properties;
          List list = new ArrayList();
          String sql = "SELECT idPrimary_key, kategori FROM kategori ";
          ResultSet hasil;
          String kategori = null;
  
          try{
              statement = con.getConnection().createStatement();
              hasil = statement.executeQuery(sql);
              while (hasil.next()) {
                  properties = new Properties();
                  properties.put("idPrimary_key", hasil.getString(1));
                  properties.put("kategori", hasil.getString(2));
                  list.add(properties);
              }
              kategori = JSONValue.toJSONString(list);
          }
          catch(Exception e){
          }
  
          return kategori;
      }
  
  
  }
  </code></pre>
  
  <p>And return a JSON like this</p>
  
  <pre><code>[{"idPrimary_key":"21ye21","kategori":"FirstCategory"},
  {"idPrimary_key":"89oy89","kategori":"SecondCategory"},
  {"idPrimary_key":"34ew34","kategori":"ThirdCategory"}]
  </code></pre>
  
  <p>And I try to consume in Android ListView like this, but still got errors,</p>
  
  <pre><code>        SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);  
  
          SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
          envelope.setOutputSoapObject(request);
  
          HttpTransportSE transportSE = new HttpTransportSE(URL);
  
          try {
              transportSE.call(SOAP_ACTION, envelope);
              SoapPrimitive response = (SoapPrimitive) envelope.getResponse();
              result = response.toString();
  
          } catch (Exception e) {
              e.printStackTrace();
  
          }
  
          String jsonAN = "{\"kat\":"+result+"}"; //try to build to be like this {"kat":[{blablablaJSON}]}
          String kategoriJSONList[][] = new String[99][2];
          String katList[] = new String[99]; //tobe shown on listview, derived from two dimensional array above.
          try {
              jsonObject = new JSONObject(jsonAN);
              jsonArray = jsonObject.getJSONArray("kat");
  
              for(int i=0; i &lt; jsonArray.length() ; i++){
                  kategoriJSONList[i][0] = jsonArray.getJSONObject(i).getString("idPrimary_key").toString();
                  kategoriJSONList[i][1] = jsonArray.getJSONObject(i).getString("kategori").toString();
              }
  
              for(int i=0; i &lt; jsonArray.length(); i++){
                  katList[i] = kategoriJSONList[i][1];
              }
  
          } catch (JSONException e) {
              // TODO Auto-generated catch block
              e.printStackTrace();
          }
  
          ListView list  = (ListView) findViewById(R.id.listKategori);
          ArrayAdapter&lt;String&gt; adapter = new ArrayAdapter&lt;String&gt;(
                  WebServiceActivity.this, android.R.layout.simple_list_item_1,katList
                  );
  
          list.setAdapter(adapter);
  
          list.setOnItemClickListener(new AdapterView.OnItemClickListener() {
  
              public void onItemClick(AdapterView&lt;?&gt; arg0, View arg1, int position,
                      long arg3) {
                  final String kategori = (String) ((TextView)arg1).getText();
                  Toast.makeText(WebServiceActivity.this, kategori,
                          Toast.LENGTH_LONG).show();
              }
          });
  </code></pre>
  
  <p>Need help how to consume the JSONValue that return as shown above to be shown as ListView.
  I got stress in this days.
  Thanks in advance.</p>