[英]How to get value from child jsonnode using java
我需要使用Java從jsonnode獲取編解碼器值。 以下是帶有父節點和子節點的jsonnode。
{
"DetectedProperties":{
"Bitrate":262610704,
"FrameRate":"24/1",
"FileSize":32827252,
"Height":1080,
"Width":1920,
"DurationMillis":1.0,
"codec":"prores"
}
}
以下代碼片段不會為編解碼器返回值。 它始終返回null。
JsonNode videoProperties = getCodecInfo(videoFile);
JsonNode videoInfo = videoProperties.get("DetectedProperties");
log.debug("codec: " + videoInfo.get("codec").toString()); // returns null
如何使用Java從上述json獲取編解碼器值?
請提供您的輸入。
您可以為此使用json表達式“ / DetectedProperties / codec”。
JsonParser parser = new JsonFactory().createParser(getCodecInfo().toString());
parser.setCodec(new ObjectMapper());
TreeNode tree = parser.readValueAsTree();
System.out.println(tree.at("/DetectedProperties/codec"));
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.