java - Convert json decimal number to short with hexadecimal value -
i have jsonobject
contains string decimal value this:
private static registerin parseregisterin(jsonobject object) { registerin toreturn = new registerin(); try { toreturn.setusername(object.getstring("username")); toreturn.setcertificate(new short(integer.tohexstring(object.get("certificate")))); } catch (jsonexception e) { e.printstacktrace(); } return toreturn; }
the certificate
object value 15879 corresponds 3e07 in hexadecimal. want recover jsonobject , save in short
attribute. , has that.
i've tried access parameter , recover posted above, following exception:
java.lang.numberformatexception: invalid int: "3e07"
how can decimal value, convert hexadecimal, , save in short value?
note:
toreturn.setcertificate(...)
is short
type.
you need use,
short.parseshort(object.getstring("certificate"), 16);
Comments
Post a Comment