Public Class YB{
Object b;
}
void Test(){
JSONObject jsonObject = new JSONObject();
jsonObject.put("test","111");
YB yb = new YB();
yb.b = jsonObject;
Gson gson = new Gson();
String s = gson.toJson(yb,YB.class);
// 此时 字符串s中,b对应的字符串值会被nameValuePair包裹一层;
// 进行处理
// JSONObject对象转为string,再转为JsonObject
JsonObject jo= gson.fromJson(jsonObject.toString(), JsonObject.class);
yb.b = jo;
String s = gson.toJson(yb,YB.class);
// 此时字符串s中,b对应的字符串值时正常的键值对了。
}
06-24
2268
2268
02-07
2455
2455

被折叠的 条评论
为什么被折叠?



