How to get each element of this array in java using android stuio

I am getting array string on responseJSON like this

Result: responseJSON = ["Product1","Product2","Product1","Product2"]

try {
        // Invole web service
        androidHttpTransport.call(SOAP_ACTION+methName, envelope);
        // Get the response
        SoapPrimitive response = (SoapPrimitive) envelope.getResponse();
        // Assign it to static variable
        responseJSON = response.toString();

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

      

how can I get each element of the array so that I can use it to display on mine ListView

?

thank

public void invokeJSONWS(String country, String methName) {
    // Create request
    SoapObject request = new SoapObject(NAMESPACE, methName);
    /*
    // Property which holds input parameters
    PropertyInfo paramPI = new PropertyInfo();
    // Set Name
    paramPI.setName("country");
    // Set Value
    paramPI.setValue(country);
    // Set dataType
    paramPI.setType(String.class);
    // Add the property to request object
    request.addProperty(paramPI);
    */
    // Create envelope
    SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(
            SoapEnvelope.VER11);
    envelope.dotNet = true;
    // Set output SOAP object
    envelope.setOutputSoapObject(request);
    // Create HTTP call object
    HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);

    try {
        // Invole web service
        androidHttpTransport.call(SOAP_ACTION+methName, envelope);
        // Get the response
        SoapPrimitive response = (SoapPrimitive) envelope.getResponse();
        // Assign it to static variable
        responseJSON = response.toString();

        JSONArray responseArr = new JSONArray(responseJSON);
        for(int i=0;i < responseArr.length();i++)
        {
            String temp=responseArr.getString(i);
            myProduct.add(new Product(responseJSON,2,R.drawable.user_awake,responseJSON));
        }

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

      

this is the method i used, it fixes that i also add add item to list view

please, help

thank

+3


source to share


1 answer


pass this string to constructor JSONAarry

like this



    ArrayList<String> mParsedList = new ArrayList<String>();
    JSONAarry responseArr=new JSONArray(responseJSON);
    for(int i=0;i<responseArr.length;i++)
    {
       String temp=responseArr.getString(i);// get one by one element 
       myProduct.add(new Product(temp,2,R.drawable.user_awake,responseJSON));
  }

      

+2


source







All Articles