java Json解析器将空值转换为0
我正在使用网络。旧金山。json库,并使用它解析我的refMap,如:
Map<String, Group> myMap = new HashMap<String,Group>();
myMap = this.getGroupValues();
JSONObject jsonObj = new JSONObject();
jsonObj.putAll(refMap);
File jsonFile = new File("./TempJson.txt");
FileWriter writer = new FileWriter(jsonFile);
fileWriter.write(jsonObj.toString());
其中我的小组课定义为:
class Group {
Double val;
Integer num;
Section sectionObj;
//..getters & setters
}
问题是this.getGroupValues()
返回一些组对象,其中val/num(包装类)值为“null”,然后JsonObject解析器将其转换为0,如:"val":0,"num":0
而如果sectionObj
为空,解析器将其保持为空,如同"sectionObj":null
如何在json文件中也为包装类对象获取空值
共 (0) 个答案