【问题标题】:Configure retrieved data from web service配置从 Web 服务检索的数据
【发布时间】:2014-04-29 08:42:10
【问题描述】:
public class MainActivity extends Activity {

private static final String SOAP_ACTION = "http://tempuri.org/xxxx/GetLatLong";

private static final String METHOD_NAME = "GetLatLong";

private static final String NAMESPACE = "http://tempuri.org/";

private static final String URL = "http://xxxx:xxxx/xxxx.svc/soap";


@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
    StrictMode.setThreadPolicy(policy); 

    TextView textView = new TextView(this);

    setContentView(textView);

    SoapObject request = new SoapObject(NAMESPACE,METHOD_NAME);

    SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
    envelope.dotNet = true;

    envelope.setOutputSoapObject(request);

    HttpTransportSE httpTransport = new HttpTransportSE(URL);



    try

    {


        httpTransport.call(SOAP_ACTION, envelope);  


        Object response = envelope.getResponse();



        textView.setText(response.toString());


    }

    catch (Exception exception)

    {

        textView.setText(exception.toString());

    }


}

}

这是我的代码示例。 这将返回一个带有 3 个数据描述 latitude 和 longitude 的字符串。

我想单独处理它们,我该如何管理? 然后我想把它放在具有该配置的地图上。

【问题讨论】:

  • 请提供响应字符串..
  • [{"Description":"1","Latitude":0.369,"Longitude":1.258},{"Description":"2","Latitude":1.369,"Longitude": 3.258},{"描述":"3","纬度":2.369,"经度":4.258}]

标签: android json soap


【解决方案1】:

编写类似这样的代码

 JSONArray array=new JSONArray("your string response in json format");
    for(int count=0;count<array.length();count++)
    {
            JSONObject obj=array.getJSONObject(count);
            String description=obj.optString("Description");
            String latitude=obj.optString("Latitude");
            String longitude=obj.optString("Longitude");

            // Logic to display latlong on map
    }

【讨论】:

  • org.json.JSONException: java.lang.String 类型的值无法转换为 JSONObject
  • 更新你的解析器代码,并给我错误的行号。
  • 这样使用而不是 optString .. String description=obj.getString("Description");
  • org.json.jsonexception value 任何类型的java.lang.string类型都不能转换成jsonarray
  • 我已经使用了你写的代码我将 optstring 更改为 getString 并且我再次收到错误 soapObject cannot be cast to java.lang.string
猜你喜欢
  • 1970-01-01
  • 2014-03-15
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多