我已經寫在asp.net MVC服務,它接受字符串化JSON對象作爲參數,我想從我的Android代碼從Android的服務呼叫收到的JSONObject是在.NET服務
消費,這是服務空方法
public JsonResult saveDataInSession(string jsonObjSend)
{
JsonResult jsonResult = null;
List<OnlineUserDetails> lstValue = new List<OnlineUserDetails>();
OnlineUserDetails UserDetails = new OnlineUserDetails();
JavaScriptSerializer jss = new JavaScriptSerializer();
UserDetails = JsonConvert.DeserializeObject<OnlineUserDetails>(jsonData);
UserDetails.LoginId = UserDetails.EmaillId;
UserLoginAndSignUp UserLoginAndSignUp = new UserLoginAndSignUp();
string result = UserLoginAndSignUp.SaveDetails(UserDetails);
jsonResult = Json(UserDetails, JsonRequestBehavior.AllowGet);
return jsonResult;
}
這該是多麼我是從Android的
jsonObjSend = new JSONObject();
try{
jsonObjSend.put("FirstName", firstname.getText().toString());
jsonObjSend.put("LastName", lastname.getText().toString());
jsonObjSend.put("EmaillId", emailid.getText().toString());
jsonObjSend.put("Password", password.getText().toString());
jsonObjSend.put("MobileNumber", mobilenumber.getText().toString());
//jsonObjSend.put("Login_RememberMe", "true");
//
}catch (JSONException e) {
e.printStackTrace();
}
發送JSON對象,使一個HttpRequest調用諸如
try {
DefaultHttpClient httpclient = new DefaultHttpClient();
HttpPost httpPostRequest = new HttpPost(URL);
StringEntity se=null;
try {
se = new StringEntity(jsonObjSend.toString(),HTTP.UTF_8);
} catch (UnsupportedEncodingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
se.setContentType("application/json");
se.setContentEncoding("UTF-8");
// Set HTTP parameters
httpPostRequest.setEntity(se);
HttpResponse response = (HttpResponse) httpclient.execute(httpPostRequest);
但是,每當我嘗試通過傳遞jsonobject消費webservice我收到空。
什麼是錯誤?
感謝您的幫助提前