ITeye博客

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

dh189 · 2010-09-01 11:08 · java · 编程语言 · Markdown

/**
	 * 解析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);
		}
	}

评论(0)

暂无评论。

评论功能维护中,当前仅展示历史评论。