如何使用android stuio在java中获取该数组的每个元素

如何使用android stuio在java中获取该数组的每个元素,java,android,arrays,json,ksoap2,Java,Android,Arrays,Json,Ksoap2,我得到responseJSON上的数组字符串,如下所示 Result: responseJSON = ["Product1","Product2","Product1","Product2"] try { // Invole web service androidHttpTransport.call(SOAP_ACTION+methName, envelope); // Get the response SoapPrimitive

我得到responseJSON上的数组字符串,如下所示

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();
    }
如何获取数组的每个元素,以便使用它在我的
列表视图中显示

谢谢

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();
    }
}
public void invokeJSONWS(字符串国家/地区,字符串名称){
//创建请求
SoapObject请求=新的SoapObject(名称空间、名称);
/*
//保存输入参数的属性
PropertyInfo paramPI=新的PropertyInfo();
//设置名称
paramPI.setName(“国家”);
//设定值
参数设置值(国家);
//设置数据类型
paramPI.setType(String.class);
//将属性添加到请求对象
request.addProperty(paramPI);
*/
//创建信封
SoapSerializationEnvelope=新的SoapSerializationEnvelope(
第11版);
envelope.dotNet=true;
//设置输出SOAP对象
envelope.setOutputSoapObject(请求);
//创建HTTP调用对象
HttpTransportSE androidHttpTransport=新的HttpTransportSE(URL);
试一试{
//发票web服务
调用(SOAP\u ACTION+methName,信封);
//得到回应
SoapPrimitive响应=(SoapPrimitive)信封.getResponse();
//将其分配给静态变量
responseJSON=response.toString();
JSONArray responseArr=新的JSONArray(responseJSON);
对于(int i=0;i
这就是我使用的方法。正确的是,我还包括在列表视图中添加项目

请帮忙


谢谢

像这样将此字符串传递给
jsonarry
构造函数

    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));
  }
ArrayList mParsedList=new ArrayList();
jsonarry responseArr=新的JSONArray(responseJSON);

对于(int i=0;我这里可能存在的问题是,您正在对象中添加responseJSON,而不是您已解析的temp变量。应为数组类型;发现:'org.json.JSONArray'是输入错误。我已更新了答案,请检查。您能在此处发布解析方法吗?将
temp
添加到,而不是
responseJSON
检查现在,您需要在代码中添加responseJSON而不是temp。