转换前:
[{
"zjlx": 201,
"xm": "刘**",
"cbdjxxlist": [{
"zspmdm": 102031201,
"rybm": "43000010300000411195",
"jfrlx": 1,
"zszmdm": "000000000",
"zsxmdm": 10203,
"sbjbjgdm": 4303994300003100000,
"ksjfny": 200912,
"dsdmname": "湘潭市本级",
"zgswjgdm": 14303040000,
"zzjfny": 209912
}],
"djxh": "20124300910055880605",
"zjhm": 43030411040
}, {
"zjlx": 201,
"xm": "刘**",
"cbdjxxlist": [{
"zspmdm": 102031701,
"rybm": "43000010300000411195",
"jfrlx": 1,
"zszmdm": "000000000",
"zsxmdm": 10203,
"sbjbjgdm": 4303994300003100000,
"ksjfny": 200912,
"dsdmname": "湘潭市本级",
"zgswjgdm": 14303040000,
"zzjfny": 209912
}],
"djxh": "20124300910055880605",
"zjhm": 43030411040
}, {
"zjlx": 201,
"xm": "刘**",
"cbdjxxlist": [{
"zspmdm": 102032602,
"rybm": "43000010300000411195",
"jfrlx": 1,
"zszmdm": "000000000",
"zsxmdm": 10203,
"sbjbjgdm": 4303994300003100000,
"ksjfny": 202109,
"dsdmname": "湘潭市本级",
"zgswjgdm": 14303040000,
"zzjfny": 209912
}],
"djxh": "20124300910055880605",
"zjhm": 43030411040
}]
转换后:
[{
"zjlx": "201",
"xm": "刘**",
"cbdjxxlist": [{
"ksjfny": "200912",
"zspmdm": "102031201",
"rybm": "43000010300000411195",
"jfrlx": "1",
"zszmdm": "000000000",
"dsdmname": "湘潭市本级",
"zgswjgdm": "14303040000",
"zsxmdm": "10203",
"sbjbjgdm": "4303994300003100000",
"zzjfny": "209912"
}],
"djxh": "20124300910055880605",
"zjhm": "4303041****1040"
}, {
"zjlx": "201",
"xm": "刘**",
"cbdjxxlist": [{
"ksjfny": "200912",
"zspmdm": "102031701",
"rybm": "43000010300000411195",
"jfrlx": "1",
"zszmdm": "000000000",
"dsdmname": "湘潭市本级",
"zgswjgdm": "14303040000",
"zsxmdm": "10203",
"sbjbjgdm": "4303994300003100000",
"zzjfny": "209912"
}],
"djxh": "20124300910055880605",
"zjhm": "4303041****1040"
}, {
"zjlx": "201",
"xm": "刘**",
"cbdjxxlist": [{
"ksjfny": "202109",
"zspmdm": "102032602",
"rybm": "43000010300000411195",
"jfrlx": "1",
"zszmdm": "000000000",
"dsdmname": "湘潭市本级",
"zgswjgdm": "14303040000",
"zsxmdm": "10203",
"sbjbjgdm": "4303994300003100000",
"zzjfny": "209912"
}],
"djxh": "20124300910055880605",
"zjhm": "4303041****1040"
}]
代码
public void modifyJsonNumberValue(Object object) {
if (object instanceof JSONObject) {
JSONObject jsonObject = (JSONObject) object;
Iterator iterator = jsonObject.entrySet().iterator();
while (iterator.hasNext()) {
Map.Entry entry = (Map.Entry) iterator.next();
Object o = entry.getValue();
if (o instanceof Long || o instanceof Integer || o instanceof Double) {
if (entry.getKey() != null) {
jsonObject.put(entry.getKey().toString(), o + "");
}
} else if (o instanceof JSONArray) {
modifyJsonNumberValue(o);
} else if (o instanceof JSONObject) {
modifyJsonNumberValue(o);
}
}
}
if (object instanceof JSONArray) {
JSONArray jsonArray = (JSONArray) object;
for (int i = 0; i < jsonArray.size(); i++) {
modifyJsonNumberValue(jsonArray.get(i));
}
}
}