java - 将在 Apex 销售人员闪电中反序列化的 Json 响应
问题描述
我通过点击 RestAPI 得到以下 Json 响应。
**
[
{
"index": 0,
"object": {
"attributes": {
"ID": [
{
"type": "configuration/entityTypes/Customer/attributes/ID",
"ov": true,
"value": "5",
"uri": "entities/attributes/ID/2Cqf5xG2"
},
{
"type": "configuration/entityTypes/Customer/attributes/ID",
"ov": true,
"value": "3028",
"uri": "entities/attributes/ID/fto38ZRR"
}
],
"IgpId": [
{
"type": "configuration/entityTypes/Customer/attributes/IgpId",
"ov": true,
"value": "1911",
"uri": "entities/attributes/IgpId/20ft8omYM"
}
],
"IgpName": [
{
"type": "configuration/entityTypes/Customer/attributes/IgpName",
"ov": true,
"value": "Dr. heath",
"uri": "entities/attributes/IgpName/20ft8oe1q"
}
],
"IgpID": [
{
"type": "configuration/entityTypes/Customer/attributes/IgpID",
"ov": true,
"value": "1872",
"uri": "entities/attributes/IgpID/20ft8oiI6"
}
],
"IgpNAME": [
{
"type": "configuration/entityTypes/Customer/attributes/IgpNAME",
"ov": true,
"value": "Dr Jc crook",
"uri": "entities/attributes/IgpNAME/20ft8oqoc"
}
]
}
},
"successful": true
}
]
**
我正在尝试将 CoachID (3028)、IgpID(1872)、IgpId(1911)、IgpName(Dr. heath)、IgpNAME(Dr Jc crook) 的值保存在 APex 类的字符串变量中。
我已经使用地图来执行此操作,但无法获得正确的值。我想在 List 中获取上述值并从函数中返回该列表。
谁可以帮我这个事?我不应该使用包装器来做到这一点。
问候,莫希特
解决方案
它不能作为直接的“JSON.deserialize”调用来完成,因为某些字段是 Apex 中的保留关键字。包装禁令有多严格?我不想徒手输入这些东西,但你可以去https://json2apex.herokuapp.com/,勾选关于显式解析器的复选框(再次,因为你已经保留了关键字,它无论如何都会发生),好吧,你有单元测试/示例如何使用代码的现成课程和酷刺。它经过了实战考验,如果你不能使用它,那么你的项目就会有更大的问题;)
如果您真的必须独自完成并使用地图,它将类似于https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_class_System_Json.htm,例如deserializeUntyped
推荐阅读
- c++ - 如何从接口获取派生类?
- scala - 如何在 intellij 中使用 scala.collection.JavaConverters?
- wordpress - 荣誉 URL 从 magento 迁移到 wordpress
- node.js - 如何使用 Express 将数据传递到不同的路由?
- php - PHP替换数组内的数组值
- postgresql - 尝试创建尚不存在的函数引用表时,pg_restore 失败
- c - 如何从 ADC(PIC16F877A)获取 int 值?
- css - 如何解决 mat-datepicker-toggle 位置问题?
- reactjs - 如何修复:ReactDOM.render() - TS2345:“() => Element”类型的参数不可分配给“ReactElement”类型的参数
- angular - 我如何解决 E/launcher - 运行 ng e2e 时在 gitlab 作业上退出进程并显示错误代码 199