c# - JsonObject received from android service call is null at .net service -
i have written service in asp.net mvc accepts stringified json object parameter , trying consume android code
this service method
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; }
and how sending json object 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(); }
and making httprequest call like
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);
but whenever try consume webservice passing jsonobject receiving null.
what's error??
thanks in advance
i think need set datatype = json when posting request along json data
in case suppose there option call this:
se.setdatatype("json");
Comments
Post a Comment