我修改了这段代码,但不起作用。如何在没有参数的情况下在 SOAP 上获取 JSON,而列表视图没有参数?. 我的图像是 JSON 数据,我在设备上测试打开的网站,它的工作。
private class LoadJS extends AsyncTask<String, String, String> {
String resultedData = null;
@Override
protected String doInBackground(String... params) {
SoapObject request = new SoapObject("http://tempuri.org/", "TESTUSERJSON");
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.dotNet = true;
envelope.setOutputSoapObject(request);
HttpTransportSE androidHttpTransport = new HttpTransportSE("http://10.0.2.2/MyService/Service.asmx?WSDL");
androidHttpTransport.debug = true;
try {
androidHttpTransport.call("http://tempuri.org/TESTUSERJSON", envelope);
SoapPrimitive response = (SoapPrimitive) envelope.getResponse();
resultedData = response.toString();
} catch (Exception ex) {
resultedData = "Error";
}
return resultedData;
}
}
杰森数据
假设你在一个名为 resultedData
的字符串中得到结果,你只需像这样正常解析它:
JSONArray jsonArray = new JSONArray(resultedData);
for (int i = 0, i < jsonArray.length(), i++) {
JSONObject jsonObject = jsonArray.get(i);
// THIS IS WHERE YOU DO WHAT YOU LIKE WITH EACH OBJECT IN THE ARRAY
String userId = jsonObject.getString("userId");
String userPwd = jsonObject.getString("userPwd");
}