【问题标题】:Json response to be deserialized in Apex salesforce lightning将在 Apex 销售人员闪电中反序列化的 Json 响应
【发布时间】:2020-07-01 16:34:23
【问题描述】:

我通过点击 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 中获取上述值并从函数中返回该列表。

谁能帮我解决这个问题?我不应该使用包装器来做到这一点。

问候, 莫希特

【问题讨论】:

    标签: java salesforce apex salesforce-lightning aura-framework


    【解决方案1】:

    它不能作为直接的“JSON.deserialize”调用来完成,因为某些字段是 Apex 中的保留关键字。包装禁令有多严格?我不想徒手输入这些东西,但你可以去https://json2apex.herokuapp.com/,勾选关于显式解析器的复选框(再次,因为你已经保留了关键字,无论如何它都会发生),好吧,你有一个现成的类和很酷的刺单元测试/示例如何使用代码。它是久经考验的,如果你不能使用它,那么你的项目就会有更大的问题;)

    如果您真的必须独自完成并使用地图,则类似于https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_class_System_Json.htm,例如deserializeUntyped

    【讨论】:

    • 谢谢,我已从 API 以字符串形式返回响应,并在 JS 中处理它并正常工作。
    • 哈,当然,这也有效。如果您真的不需要 Apex 中的结果,那么解析它们会浪费时间,只需直接传递它们 :)
    猜你喜欢
    • 2012-04-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-04-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多