Skip to content
This repository was archived by the owner on Jul 29, 2026. It is now read-only.

JSONPath_Extract

温绍锦 edited this page Oct 1, 2018 · 2 revisions

1.2.51之后,fastjon提供了根据JSONPath快速解析JSON的API,避免原来需要先解析完再做JSONPath处理,能显著提升性能。

API

packagecom.alibaba.fastjson;
publicclassJSONPath {
publicstaticObjectextract(Stringjson, Stringpath);
}

DEMO

final String json = "[\n" +
" {\n" +
" \"name\" : \"john\",\n" +
" \"gender\" : \"male\"\n" +
" },\n" +
" {\n" +
" \"name\" : \"ben\"\n" +
" }\n" +
"]";
String result = JSONPath.extract(json, "$[0]['name','gender']").toString();
assertEquals("[\"john\",\"male\"]", result);

Clone this wiki locally