Type casting error while parsing json response for int value in java -


i parsing below json , want fetch value of enterpriseflag

"cardholderdetails":  {             "firstname": "manoj",             "lastname": "pandy",             "profileimageurl": "https://www.mark.com/imagelinkimages/mk0557/pandey,manoj_500617996.jpg",             "buildingnumber": "mk0557",             "cardholderinstid": 0,             "enterpriseflag": 6 } 

below code

int cardholderinstid = cardholderdetail.get("cardholderinstid");     system.out.println(cardholderinstid); 

it shows error type mismatch: cannot convert object int , shows option cast integer,

int cardholderinstid = (integer) cardholderdetail.get("cardholderinstid"); system.out.println(cardholderinstid); 

if cast integer , prints value shows error. (exception in thread "main" java.lang.classcastexception: java.lang.long cannot cast java.lang.integer @ com.jason.example.jasonparser.readjson.main)

please !!! in advance..

it looks json parser you're using parsing cardholderinstid long instead of integer.

cast long use intvalue() method on object int.


Comments

Popular posts from this blog

wordpress - (T_ENDFOREACH) php error -

Export Excel workseet into txt file using vba - (text and numbers with formulas) -

Using django-mptt to get only the categories that have items -