symfony反序列化为具有不同密钥的对象



从API得到这样的输出:

{
"type": "string",
"code": "string",
"addInfo2": "",
"addInfo3": "23536723462",
"addInfo4": null,
"addInfo5": null,
"arrow": "none",
"IdList": [
"2357789234"
],
"templateName": null,
"rotationDegrees": "0"
}

现在我想通过调用将这个jsonstring反序列化为一个Object

$this->序列化程序->反序列化($jsonLabelMappings,LabelMappings::class,'json');

但我希望对象有其他键/属性名称。我的对象应该是这样的:

{
"type": "string",
"code": "string",
"originCountry": "", /* this is the addInfo2 */
"gtin": "23536723462", /* this is the ddInfo3 */
"wildfang": null, /* this is the addInfo4 */
"arrow": "none",
"ids": [ /* this is the articleIdList */
"2357789234"
],
"templateName": null,
"rotationDegrees": "0"
}

有没有类似@Serializer\DeserializeName之类的站点?或者,我如何告诉我的代码json中的keyName是其他东西?

因为我没有得到任何答案来解决我的注释或其他问题"短";。我现在用@Fly_Moe回答:

将json转换为数组应该很容易做到。循环遍历数组并用新的密钥替换密钥。这就是我要做的

最新更新