`
dh189
  • 浏览: 132918 次
  • 性别: Icon_minigender_2
  • 来自: 上海
社区版块
存档分类
最新评论

使用jackson解析json数据时获取多级节点的值,递归实现

    博客分类:
  • java
阅读更多

/**
	 * 解析jsonNode的值
	 * @param node 
	 * @param attrs "aa.bb.cc"
	 * @return
	 */
	public static String getJsonNodeValue(JsonNode node, String attrs) {
		int index = attrs.indexOf('.');
		if (index == -1) {
			if (node != null && node.get(attrs) != null) {
				return node.get(attrs).getValueAsText();
			}
			return "";
		} else {
			String s1 = attrs.substring(0, index);
			String s2 = attrs.substring(index + 1);
			return getJsonNodeValue(node.get(s1), s2);
		}
	}
 
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics