---
title: "使用jackson解析json数据时获取多级节点的值，递归实现"
author: "dh189"
date: "2010-09-01T11:08:40Z"
tags: []
categories: ["编程语言"]
slug: "jackson-json"
draft: false
lastmod: "2010-09-01T11:08:40Z"
id: 752471
url: "https://dh189.iteye.com/blog/752471"
---

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