1、后台接受到前台的json格式的字符串处理方式
String jsonStr = "{\"password\":\"\",\"username\":\"张三\"}" ;
JSONObject jsonObj = JSONObject.fromString(jsonStr);
2、后台拼装json格式的字符串
JSONObject jsonObj = new JSONObject();
jsonObj.put( "username" ,"张三" );
3、json格式的字符串转换xml格式的字符串
String jsonStr = "{\"password\":\"\",\"username\":\"张三\"}" ;
JSONObject json = JSONObject.fromString(jsonStr);
XMLSerializer xmlSerializer = new XMLSerializer();
xmlSerializer.setRootName( "user_info" );
xmlSerializer.setTypeHintsEnabled( false );
String xml = xmlSerializer.write(json);
4、xml格式的字符串转换为json格式的字符串
String xml =
"<?xml version=\".\" encoding=\"UTF-\"?><user_info><password></password><username>张三</username></user_info>" ;
JSON json=XMLSerializer.read(xml);
5、javabean转换为json字符串
UserInfo userInfo = new UserInfo();
userInfo.setUsername( "张三" );
userInfo.setPassword( "" );
JSONObject json = JSONObject.fromBean(userInfo);