java - 使用 JsonPath 使用链接的 hashmap java 解析 Json
问题描述
我有一些包含链接哈希图的 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"
}
}
}
解决方案
推荐阅读
- html - 是否可以在 Angular 组件中解析 templateURL?
- android - 从存储在 StreamingDataPath 中的图像加载纹理
- python - 操作列表和字典
- javascript - 如何在 ChartsJS 中换行标签对象(嵌套数组不起作用)
- python - 如何从python中的数组中删除对象?
- r - 如何在使用本地持久存储时立即更新 dataTableOutput
- html - HTML - 导航栏的背景颜色不会改变
- python - 刚刚定义了一个新变量,现在程序陷入了无限循环
- php - 为联系表 7 创建邮件计数器
- raspberry-pi - Arducam 不工作,mmal 没有从传感器错误中收到数据?