📅  最后修改于: 2020-11-18 09:05:55             🧑  作者: Mango
ObjectMapper类也可以用于将json解析为Map对象,而不是POJO对象。
以下示例使用ObjectMapper类将JSON字符串解析为Map Object。
import java.util.Map;
import org.boon.json.JsonFactory;
import org.boon.json.ObjectMapper;
public class BoonTester {
public static void main(String args[]) {
ObjectMapper mapper = JsonFactory.create();
String jsonString = "{\"name\":\"Mahesh\", \"age\":21}";
Map studentMap = mapper.readValue(jsonString, Map.class);
System.out.println("Name: " + studentMap.get("name"));
System.out.println("Age: " + studentMap.get("age"));
}
}
Name: Mahesh
Age: 21