java - How to get AsyncHttpResponseHandler response as a JSONObject? -


my java restful service login method returns jsonobject (with name, username, , on) in responsebuilder entity. i'm trying inside asynchttpresponsehandler (using loopj) in android app. problem is: onsuccess method expecting byte[] response, not jsonobject. how jsonobject inside onsuccess method in order use it's values (user data) on app?

here code:

my restful api login method

public response login(@context httpheaders httpheaders,             @formparam("username") string username,             @formparam("password") string password) {          authenticator authenticator = authenticator.getinstance();         string servicekey = httpheaders                 .getheaderstring(httpheadernames.service_key);          try {             // login method returns jsonobject data of logged user             jsonobject obj = authenticator                     .login(servicekey, username, password);              return getnocacheresponsebuilder(response.status.ok).entity(obj)                     .build();          } catch (final loginexception ex) {             return getnocacheresponsebuilder(response.status.unauthorized)                     .entity(ex.getmessage()).build();         }     } 

login method on app:

 private void logintask(requestparams params){     apprestclient.post("access/login", params, new asynchttpresponsehandler() {          @override         public void onsuccess(int statuscode, header[] headers, byte[] response) {                           // here want jsonobject, response             // returning [b@653abba             log.d(tag, response);          }         ...   } 

should transform byte[] jsonobject (if yes, how can that?) or should change responsebuilder entity return different jsonobject?

i tried use jsonhttpresponsehandler class response empty.


Comments

Popular posts from this blog

python - Healpy: From Data to Healpix map -

c - Bitwise operation with (signed) enum value -

xslt - Unnest parent nodes by child node -