繁体   English   中英

如何使用Java从子jsonnode获取值

[英]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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM