我有这个字符串,我使用 ObjectMapper 将它覆盖到 jsonNode。然后我试图在这个 jsonNode 中寻找一个特定的键,所以我使用了“.has”但它没有用!这是我所做的:
{
"links": {
"data": {
"self": {
"body": "",
"content_type": "",
"href": "/api/v2/nodes",
"method": "POST",
"name": ""
}
}
},
"results": {
"data": {
"properties": {
"container": true,
"container_size": 0,
"create_date": "2020-06-22T16:19:07",
"create_user_id": 1000,
"description": ""
"description_multilingual": {
"en": "",
"fr_FR": ""
},
"external_create_date": null,
"external_identity": "",
"external_identity_type": "",
"external_modify_date": null,
"external_source": "",
"favorite": false,
"id": 276625,
"mime_type": null,
"modify_date": "2020-06-22T16:19:07",
"modify_user_id": 1000,
"name": "mar",
"name_multilingual": {
"en": "mar",
"fr_FR": ""
},
"owner": "Admin",
"owner_group_id": 1001,
"owner_user_id": 1000,
"parent_id": 2000,
"permissions_model": "advanced",
"reserved": false,
"reserved_date": null,
"reserved_shared_collaboration": false,
"reserved_user_id": 0,
"size": 0,
"size_formatted": "0 Eléments",
"type": 0,
"type_name": "Dossier",
"versions_control_advanced": false,
"volume_id": -2000
}
}
}
}
我想测试它是否有“id”键(它实际上存在于第 31 行)所以我使用.has()
了如何检查 json 键是否存在?:
ObjectMapper mapper = new ObjectMapper();
JsonNode rootNode= mapper.readTree(body);
if(rootNode.has("id")){
System.out.println(true);
}
else{
System.out.println(false);
}
但它总是向我显示“假”作为输出!