1 .分析简单的josn格式字符串
String msg='{'rs':0,' fs': '登录成功! () );
jonobjectjsonobject=newjsonobject (msg;
system.out.println (JSON object.getstring (' fs ' ) )
分析json数组格式的字符串
stringjsonstr=' [' assign no' :' 201310091540', ' delivery status' :', ' 333333365365306; ' deliveryStatus':'33333'、'deliverystatus'3333。 ' imgstr' :' 1381314903597.png','remark':'", ' username' 333365374; ' zhangsan
jsonarrayjsonarray=JSON array.from object (JSON str );
Object[] objs=jsonArray.toArray (;
for(objectobject:objs ) {
jsonobjectjsonobject=JSON object.from object (object );
if(JSONobject.Has(imgstr ) ) )。
system.out.println (JSON object.getstring (' imgstr ' );
}
system.out.println (JSON object.getstring (' assign no ' );
}
stringJsonstr=sendpost(URL、para、false ); jsonobjectjsonobject=JSON object.from object (JSON str; if (JSON object.get boolean (' success ' )==true ) )。
//成功登录的返回真; }else{
logger.error ('输入密码错误!' );
返回假; }
以下是通过maven添加依存关系
net.SF.JSON-lib JSON-lib 2.4 JDK 15
排除roles属性而不序列化
jsonconfigjsonconfig=newjsonconfig (;
Jon config.set excludes (new string [ ] { ' roles ' };
请注意,如果json对象包含空值,则转换将出错
JSONobject.fromobject(JSON,jsonConfig );