android studio中的代码是什么 [英] What is the code in android studio
本文介绍了android studio中的代码是什么的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
请参见下面的URL
这将返回如下所示的JSON对象.
This will return a JSON object like below.
{
"UserID": "1",
"Username": "test@test.com",
"Token": "KOSEPO1DSJSMVIF3JNHGGG4SBVKW3QVNMKNI0Q1FN18SWDOL2L"
}
获得响应的代码是什么
推荐答案
如果您使用SOAP,则应这样做:
if you use SOAP do sth like this :
String namespace = "http://tempuri.org/" ;
String soapAction = "http://tempuri.org/MyMethod";
String methodName = "MyMethod";
String url = "http://192.168.1.2:8686/WebService/MyWebService.asmx" ; // my local or valid ip for webservice location
SoapObject request = new SoapObject(namespace, methodName);
// your webservice argument
String username = "your username";
PropertyInfo usernameProp = new PropertyInfo();
usernameProp.setName("username");
usernameProp.setValue(username);
usernameProp.setType(String.class);
request.addProperty(usernameProp);
String pass = "your password";
PropertyInfo passProp = new PropertyInfo();
passProp.setName("password");
passProp.setValue(pass);
passProp.setType(String.class);
request.addProperty(passProp);
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.dotNet = true;
envelope.setOutputSoapObject(request);
HttpTransportSE androidHttpTransport = new HttpTransportSE(url);
androidHttpTransport.call(soapAction, envelope);
SoapPrimitive response = (SoapPrimitive) envelope.getResponse();
String json = response.toString();
json = "{\"data\":" + json + "}";
JSONObject mainJson = new JSONObject(json);
JSONArray jsonArray = mainJson.getJSONArray("data");
ArrayList<HashMap<String, String>> list = new ArrayList<HashMap<String, String>>();
for (int i = 0; i < jsonArray.length(); i++) {
JSONObject objJson = jsonArray.getJSONObject(i);
HashMap<String , String> map = new HashMap();
map.put("UserID" , objJson.getString("UserID"));
map.put("Username" , objJson.getString("Username"));
map.put("Token" , objJson.getString("Token"));
list.add(map)
}
//use your list
这篇关于android studio中的代码是什么的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文