can't cast jsonnull to string null 的解决

今天写代码的时候要完成接收json数据转换成map对的功能

传进来的是

{appIntroduction=null,

appScene=null,

appId="123",

callbackurl="http://zdwssq.picp.net/QiWei/userInfo?corpId=$CORPID$",

appName="新的3",

appLogoname="6d5e965c-80af-4782-9bca-af914099043dicon_6.png",

appIntroImage=null,

appSuiteId="tj8eabd12547d13d3d"

}

在map.get("appIntroduction")时候报错 can't cast jsonnull to string null.

很奇怪明明是字符串null 为什么变成jsonnull 了

查资料发现,net.sf.json 中 会判断如果value =null 会自动把null 转化为jsonnull 不懂为什么=.= 

所以加个判断就好了

Object o= map.get(key);

String str= "";

if( o instanceof JSONNull)

  value= map.get(key);

else

  .......

 

如果是org的json 返回的就是string null

 

posted @ 2016-08-01 15:00  Frank_zsx  阅读(488)  评论(0编辑  收藏  举报