从Web服务配置检索的数据

时间:2014-04-29 08:42:11

标签: android json soap

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个数据描述纬度和经度的字符串。

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

1 个答案:

答案 0 :(得分:0)

编写类似这样的代码

 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
    }