0
그래서 JSON을 스칼라로 파싱하고 있습니다. 때때로 null 인 객체가 있습니다. 어떻게해야합니까?스칼라 - null JSON 객체 다루기
나는 if (json.get("object") != null) {...}
이 효과가있을 것이라고 생각하지만 그렇지 않습니다. JSON을 구문 분석 할 때
import org.json._
val json: JSONObject = new JSONObject("{\"object\": null}")
if (json.get("object") != null) {
println("The object is not null") //This like is executed
} else {
println("the object is null") This line is not executed
}
println(json.getString("object")) //This line returns "org.json.JSONException: JSONObject["object"] not a string."
그래서 내가 어떻게 널 포인터 예외를 방지 할 수 있습니다
이
나는에 코드를 실험했습니다입니까?
를 사용으로부터 검사하는
JSONObject.NULL
보다는null
사용'공개 부울 isNull에 (자바를 사용 _null_ 값에 대하여 검사하기위한 _null_ – Mubin보다는 JSONObject.NULL를 사용한다. lang.String key)' – Mubin
JSONObject.NULL이 작동했습니다. 감사합니다. – Jones