我正在阅读JSONObject
作为输入,我正在使用id
API的getString()
方法检索密钥“net.sf.json
”的值但我很好奇知道为什么它不会进入if块..
INPUT:
{
"id" : null
}
代码:
//reading the jsonObject from String
JSONObject jsonObject.fromObject(someString);
String id = jsonObject.getString("id");
if( id == null)
{
//the control is not going in this if condition
}
答案 0 :(得分:0)
在license.Validate()
.AssertThat(lic => lic.ProductFeatures.Get("HardwareId") == "133456", new GeneralValidationFailure() { Message="Invalid Hardware.", HowToResolve="Contact administrator"});
检查后使用optString("id",null)
,当您不确定JSON格式是否相同并处理isNull()
时。{/ p>
NPE
或
JSONObject jO=jsonObject.fromObject(someString);
String id = jO.optString("id",null);
if(jO.isNull("id"))
{
//the control is not going in this if condition
}
else{
}