JSON解析字符串,null变成了"null"

2019独角兽企业重金招聘Python工程师标准>>> hot3.png

public static void main(String[] args) { String data = "{"code":null,"msg":null,"data":null,"opcode":"1","reason":"成功","result":{"firstGameData":null,"playerGameAccount":"zero","lastGameData":null}}"; JSONObject jsonResult = JSONObject.fromObject(data); JSONObject result = jsonResult.getJSONObject("result");

	System.out.println(result);
	System.out.println(result.getJSONObject("firstGameData"));
	System.out.println(result.getJSONObject("firstGameData").isNullObject());
}

解析结果: {"firstGameData":null,"playerGameAccount":"zero","lastGameData":null} null true 解决办法: JsonObject有一个方法是判断value是否为空,JsonObject.isNull(key)。解析前使用此方法判断下json对象即可。

转载于:https://my.oschina.net/u/3457493/blog/1569201

你可能感兴趣的:(JSON解析字符串,null变成了"null")