首页 > 解决方案 > 如何合并两个 JSON,其中一个 JSON 将具有实际响应,另一个将提供配置

问题描述

我有actual Response如下:

{
    "ClassifierId": "abc1",
    "results": [{
            "Input": "Input data1",
            "Score": 0.9,
            "Prediction": "Prediction1"
        },
        {
            "Input": "Input data2",
            "Score": 0.1,
            "Prediction": "Prediction1"
        }
    ]
}

并且需要config-json如下绑定:

[{
    "type": "",
    "row": [{
            "header": "",
            "col": [{
                "data": [{

                        "label": "Score",
                        "valueMapping": "@^results[i].Score",
                        "displayType": "vertical"
                    },
                    {
                        "label": "Prediction",
                        "valueMapping": "@^results[i].Prediction",
                        "displayType": "vertical"
                    }
                ]
            }]
        },
        {
            "header": "",
            "col": [{
                "data": [{
                    "label": "Text",
                    "valueMapping": "@^results[i].Input",
                    "displayType": "vertical"
                }]
            }]
        }
    ]
}]

我的实际响应可能与 api 响应不同,但我只需要配置配置 JSON。'"@^results[i].***"' 是来自实际 JSON 的相应值。'@^' 用于标识映射值。

我尝试了几种方法,但不幸的是没有运气,请指导/指导/帮助

标签: javascriptangular

解决方案


推荐阅读