Closed
Description
问题描述
以下是我的JSON数据
{
"objects": [
{
"objclass": "GamePropertySheet",
"aliases": [
"DefaultGameProps"
],
"objdata": {
"Plants": [
"plant1",
"plant2"
]
}
}
]
}
我使用的JSONPath为:$.objects[?(@.aliases[0] == 'DefaultGameProps')].objdata
目的为需要返回objdata此JSONObject
但运行时报错:
Exception in thread "main" com.alibaba.fastjson2.JSONException: not support operator :
at com.alibaba.fastjson2.JSONPath.parseOperator(JSONPath.java:1018)
at com.alibaba.fastjson2.JSONPathParser.parseFilter(JSONPathParser.java:711)
at com.alibaba.fastjson2.JSONPathParser.parseArrayAccess(JSONPathParser.java:254)
at com.alibaba.fastjson2.JSONPathParser.parse(JSONPathParser.java:95)
at com.alibaba.fastjson2.JSONPath.of(JSONPath.java:475)
at com.alibaba.fastjson2.JSONPath.eval(JSONPath.java:70)
环境信息
请填写以下信息:
- OS信息: WIndows 11 23H2 (22631.3007)
- JDK信息: OracleJDK 21
- 版本信息:Fastjson2 2.0.47
重现步骤
Kotlin:
fun main() {
val str = """
{
"#comment": "All PropertySheet objects should go here",
"version": 1,
"objects": [
{
"objclass": "GamePropertySheet",
"aliases": [
"DefaultGameProps"
],
"objdata": {
"Plants": [
"plant1",
"plant2"
]
}
}
]
}
""".trimIndent()
println(JSONPath.eval(str,"$.objects[?(@.aliases[0] == 'DefaultGameProps')].objdata"))
}
期待的正确结果
{"Plants": ["plant1","plant2"]}