更新时间:2023-11-25 23:53:10
使用以下代码查找键是否在JsonObject
中存在. has("key")
方法用于在JsonObject
中查找键.
Use below code to find key is exist or not in JsonObject
. has("key")
method is used to find keys in JsonObject
.
containerObject = new JSONObject(container);
//has method
if (containerObject.has("video")) {
//get Value of video
String video = containerObject.optString("video");
}
如果使用optString("key")
方法获取String值,则不必担心JsonObject
中是否存在键.
If you are using optString("key")
method to get String value then don't worry about keys are existing or not in the JsonObject
.