Android问题—我有一个soap web服务,希望使用json解析
我是json解析新手 我的问题是如何进行json解析我有一个登录页面,想转到主页如何进行json解析请一步一步地指导我,如果有代码wil使用XML作为数据格式,json和XML是不同的格式。因此,您必须决定使用哪种方法。Android问题—我有一个soap web服务,希望使用json解析,android,Android,我是json解析新手 我的问题是如何进行json解析我有一个登录页面,想转到主页如何进行json解析请一步一步地指导我,如果有代码wil使用XML作为数据格式,json和XML是不同的格式。因此,您必须决定使用哪种方法。//web方法 //web method public static String UserLogin(String userName, String password) { String METHOD_NAME = "Sign_Me_In_Thru_Mobile
//web方法
//web method
public static String UserLogin(String userName, String password) {
String METHOD_NAME = "Sign_Me_In_Thru_MobileApp";
String SOAP_ACTION = "http://tempuri.org/Sign_Me_In_Thru_MobileApp";
try {
SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
request.addProperty("user", userName);
request.addProperty("password", password);
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(
SoapEnvelope.VER11);
new MarshalBase64().register(envelope); // serialization
envelope.dotNet = true;
Log.d("test", "URL = " + URL);
Log.d("test", "request= " + request.toString());
envelope.setOutputSoapObject(request);
HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);
androidHttpTransport.call(SOAP_ACTION, envelope);
SoapPrimitive response = (SoapPrimitive) envelope.getResponse();
if (response != null) {
res = response.toString();
} else {
res = "0";
}
Log.d("test", "getService_Login response = " + res);
} catch (Exception e) {
Log.d("test", "Error - " + e.toString());
res = "Error";
}
return res;
}
//asynctask here for parsing json
private class CreateUserLogin extends AsyncTask<Void, Void, Void> {
String response = null;
@Override
protected void onPreExecute() {
pDialog = new ProgressDialog(UserLogin.this);
pDialog.setIndeterminate(false);
pDialog.setMessage("");
pDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
pDialog.setCancelable(false);
pDialog.show();
}
@Override
protected Void doInBackground(Void... params) {
// TODO Auto-generated method stub
response = WebCall.UserLogin(Input_UserName.getText().toString(),
Input_Password.getText().toString());
// Response=WebCall.GetCommisiioning("8087681884", 5);
// Response=WebCall.GetComplaintsService(25, 1);
return null;
}
@Override
protected void onPostExecute(Void result) {
// TODO Auto-generated method stub
super.onPostExecute(result);
Utils.ShowLogd(response);
try {
JSONArray ja = new JSONArray(response);
for (int i = 0; i < ja.length(); i++) {
JSONObject job = ja.getJSONObject(i);
userID=job.getInt("id");
DataSource.SaveDataToPre_Int(getApplicationContext(), AppConstant.USER_DETAILS, AppConstant.User_ID, job.getInt("id"));
Intent intent = new Intent(getApplicationContext(),
Search_Service.class);
startActivity(intent);
}
} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
pDialog.dismiss();
}
}
公共静态字符串UserLogin(字符串用户名、字符串密码){
字符串方法\u NAME=“在\u到\u MobileApp中签名”;
字符串SOAP_ACTION=”http://tempuri.org/Sign_Me_In_Thru_MobileApp";
试一试{
SoapObject请求=新的SoapObject(名称空间、方法名称);
request.addProperty(“用户”,用户名);
request.addProperty(“密码”,password);
SoapSerializationEnvelope=新的SoapSerializationEnvelope(
第11版);
新的MarshalBase64().寄存器(信封);//序列化
envelope.dotNet=true;
Log.d(“测试”,“URL=“+URL”);
Log.d(“test”、“request=“+request.toString());
envelope.setOutputSoapObject(请求);
HttpTransportSE androidHttpTransport=新的HttpTransportSE(URL);
调用(SOAP_操作,信封);
SoapPrimitive响应=(SoapPrimitive)信封.getResponse();
if(响应!=null){
res=response.toString();
}否则{
res=“0”;
}
Log.d(“测试”、“获取服务\登录响应=“+res”);
}捕获(例外e){
Log.d(“测试”,“错误-”+e.toString());
res=“错误”;
}
返回res;
}
//asynctask用于解析json
私有类CreateUserLogin扩展了异步任务{
字符串响应=null;
@凌驾
受保护的void onPreExecute(){
pDialog=newprogressdialog(UserLogin.this);
pDialog.setUndeterminate(假);
pDialog.setMessage(“”);
pDialog.setProgressStyle(ProgressDialog.STYLE_微调器);
pDialog.setCancelable(假);
pDialog.show();
}
@凌驾
受保护的Void doInBackground(Void…参数){
//TODO自动生成的方法存根
response=WebCall.UserLogin(输入\u UserName.getText().toString(),
输入_Password.getText().toString());
//Response=WebCall.getcommissioning(“8087681884”,5);
//响应=WebCall.GetComplaintsService(25,1);
返回null;
}
@凌驾
受保护的void onPostExecute(void结果){
//TODO自动生成的方法存根
super.onPostExecute(结果);
Utils.ShowLogd(响应);
试一试{
JSONArray ja=新JSONArray(响应);
对于(int i=0;i
所以这不是soap服务?在soap服务中是可能的