-
Notifications
You must be signed in to change notification settings - Fork 511
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[BUG]json字段有多个数组时,解析arr1数组的字段值时得到了arr2数组的结果 #1130
Comments
String raw = "{\"arr1\":[\"a\"],\"numeric\":1,\"arr2\":[\"b\"]}";
Object result = JSONPath.eval(raw, "$.arr2[0]");
assertEquals("b", result); 我测试没发现问题啊 |
补了几个测试用例;case2和case5是正常的,但是case3和case4测下来有问题
|
https://oss.sonatype.org/content/repositories/snapshots/com/alibaba/fastjson2/fastjson2/2.0.25-SNAPSHOT/ 可以说下你使用场景么? |
@wenshao 也许JSONPathTypedMultiIndexes还存在缺陷,补充case @Test
public void testArrayParseCase6() {
String raw = "{\"arr1\":[\"a\"],\"numeric\":1,\"arr2\":[\"a\"]}";
JSONPath path = JSONPath.of(new String[]{"$.arr2[0]", "$.arr2[0]"}, new Type[]{String.class, String.class});
Object[] results = (Object[]) path.extract(raw);
assertArrayEquals(new Object[]{"a", "a"}, results);
} 运行结果: |
我对你的PR做了一个性能优化,在没有重复index时,不做额外的计算。 可以分享下你的使用场景么?我对大家怎么用这个功能需要反馈 |
@wenshao 感谢您对我这个PR斧正。 |
@wenshao 我们主要在大数据场景下,通过 fastjson2 实现 json udf 来加速 json 的解析。所以相关的 issue 会比较多。 数据场景就是常见的日志解析,大 json 中获取少量的字段出来进行处理。 |
另外之前的一个 issue 下的补充,貌似还没解决,也是相关的#1070: // 测试不通过,返回的是嵌套数据 "[[[{\"a\":1},{\"a\":2}],[{\"a\":3}]]]";
String raw = "[[{\"a\":1},{\"a\":2}],[{\"a\":3}]]";
Assert.assertEquals("[[{\"a\":1},{\"a\":2}],[{\"a\":3}]]",
((JSONArray) JSONPath.extract(raw, "$")).toJSONString());
// 测试通过
Assert.assertEquals("[[{\"a\":1},{\"a\":2}],[{\"a\":3}]]";,
((JSONArray) JSONPath.extract(raw, "$[*]")).toJSONString()); |
@Leoyzen |
问题描述
利用fastjson2解析对应的数组字段不能得到期望结果
环境信息
重现步骤
如何操作可以重现该问题:
解析json字段 "{"arr1":["a"],"numeric":1,"arr2":["b"]}",期望得到数组arr2中的第一个值b,但输入arr2[0]后,得到的是arr1数组中的值a。
The text was updated successfully, but these errors were encountered: