问 题
Please see below URL
This will return a JSON object like below.
{ "UserID": "1", "Username": "test@test.com", "Token": "KOSEPO1DSJSMVIF3JNHGGG4SBVKW3QVNMKNI0Q1FN18SWDOL2L" }
What will be the code to get a response
解决方案
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
问 题
请参阅下面的URL
这将返回如下所示的JSON对象。
{
UserID”: 1”,
用户名”: test@test.com”,
令牌”: KOSEPO1DSJSMVIF3JNHGGG4SBVKW3QVNMKNI0Q1FN18SWDOL2L”
}
获得响应的代码是什么
解决方案
如果您使用SOAP,则应执行以下操作:
字符串命名空间= http://tempuri.org /”;
String soapAction = http://tempuri.org/MyMethod”;
String methodName = MyMethod”;
字符串url = http://192.168.1.2:8686/WebService/MyWebService.asmx”; //我的Web服务位置的本地或有效ip
SoapObject request = new SoapObject(namespace,methodName);
//您的网络服务参数
字符串username = your username”;
PropertyInfo usernameProp = new PropertyInfo();
usernameProp.setName( username”);
usernameProp.setValue(username);
usernameProp.setType(String.class);
request.addProperty(usernameProp);
字符串传递=您的密码”;
PropertyInfo passProp = new PropertyInfo();
passProp.setName( password”);
passProp.setValue(pass);
passProp.setType(String.class);
request.addProperty(passProp);
SoapSerializationEnvelope信封=新的SoapSerializationEnvelope(SoapEnvelope.VER11);
信封.dotNet = true;
wallet.setOutputSoapObject(request);
HttpTransportSE androidHttpTransport = new HttpTransportSE(url);
androidHttpTransport.call(soapAction,信封);
SoapPrimitive响应=(SoapPrimitive)信封.getResponse();
字符串json = response.toString();
json = {\” data\:” + json +}”;
JSONObject mainJson =新的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)
}
//使用您的列表
本文地址:IT屋 » android studio中的代码是什么
问 题
请参阅下面的URL
这将返回如下所示的JSON对象。
{
“ UserID”:“ 1”,
“用户名”:“ test@test.com”,
“令牌”:“ KOSEPO1DSJSMVIF3JNHGGG4SBVKW3QVNMKNI0Q1FN18SWDOL2L”
}
获得响应的代码是什么
解决方案
如果您使用SOAP,则应执行以下操作:
字符串命名空间=“ http://tempuri.org /”;
String soapAction =“ http://tempuri.org/MyMethod”;
String methodName =“ MyMethod”;
字符串url =“ http://192.168.1.2:8686/WebService/MyWebService.asmx”; //我的Web服务位置的本地或有效ip
SoapObject request = new SoapObject(namespace,methodName);
//您的网络服务参数
字符串username =“ your username”;
PropertyInfo usernameProp = new PropertyInfo();
usernameProp.setName(“ username”);
usernameProp.setValue(username);
usernameProp.setType(String.class);
request.addProperty(usernameProp);
字符串传递=“您的密码”;
PropertyInfo passProp = new PropertyInfo();
passProp.setName(“ password”);
passProp.setValue(pass);
passProp.setType(String.class);
request.addProperty(passProp);
SoapSerializationEnvelope信封=新的SoapSerializationEnvelope(SoapEnvelope.VER11);
信封.dotNet = true;
wallet.setOutputSoapObject(request);
HttpTransportSE androidHttpTransport = new HttpTransportSE(url);
androidHttpTransport.call(soapAction,信封);
SoapPrimitive响应=(SoapPrimitive)信封.getResponse();
字符串json = response.toString();
json =“ {\” data\“:” + json +“}”;
JSONObject mainJson =新的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)
}
//使用您的列表
本文地址:IT屋 » android studio中的代码是什么
问 题
Please see below URL
This will return a JSON object like below.
{ "UserID": "1", "Username": "test@test.com", "Token": "KOSEPO1DSJSMVIF3JNHGGG4SBVKW3QVNMKNI0Q1FN18SWDOL2L" }
What will be the code to get a response
解决方案
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

扫一扫关注IT屋
微信公众号搜索 “ IT屋 ” ,选择关注与百万开发者在一起