我有一些包含链接 HashMap 的 json,我可以像这样使用 gson 获取我想要的元素
Gson gson = new GsonBuilder().create()
JsonObject job = gson.fromJson(message.getBody(), JsonObject.class)
JsonElement entry=job.getAsJsonObject("MessageAttributes").getAsJsonObject("eventId").get("Value")
我想使用像这样的 JsonPath
JsonObject j = JsonPath.read(awsBody, "$['MessageAttributes']")
j.getAsJsonObject("eventId").get("Value")
尽管这给了我错误No such instance method: 'com.google.gson.JsonObject java.util.LinkedHashMap.getAsJsonObject (java.lang.String)'
这是我的 json
{
"MessageId": "8342fb55-9db8-42cb-8f59-c6abc8039b72",
"Type": "Notification",
"Timestamp": "2020-04-15T14:40:06.927960Z",
"Message": "Some message here ",
"TopicArn": "arn:aws:sns:us-east-1:000000000000:quote-event",
"MessageAttributes": {
"eventId": {
"Type": "String",
"Value": "HELLO-WORLDaaa-4bb04d9e-2522-4918-98c9-5a88094d3a3a"
}
}
}
最佳答案
要获取value
键,则为:
$['MessageAttributes']['eventId']['Value']
或 $.MessageAttributes.eventId.Value
关于java - 使用 JsonPath 解析带有链接 hashmap java 的 Json,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61232204/