【发布时间】:2021-10-15 21:17:16
【问题描述】:
所以我有以下回应:
{
"errors": [
{
"errorKey": "ERROR_NO_DELIVERY_OPTIONS",
"errorParameters": "[{\"errorMessage\":\"ERROR_DELIVERY_OPTIONS_YOU_SELECTED_NOT_AVAILABLE_NOW\",\"partNumbers\":[\"19308033\",\"19114798\"]},{\"errorMessage\":\"Pickup At Seller not available for these orderItemIds\",\"orderItemIds\":[\"10315031\",\"10315032\"],\"availableShipModeId\":\"13201\"}]",
"errorMessage": "ERROR_NO_DELIVERY_OPTIONS",
"errorCode": "ERROR_NO_DELIVERY_OPTIONS"
}
]
}
不幸的是,我不确定如何使用“errorParameters”的值,因为它只是一个字符串,而不是像其他的简单键值。我将如何提取所有信息以便我可以使用它。一位同事提到解析它,但不确定他的意思是什么以及如何。下面是一个更具可读性的值。我正在使用 javascript。
[
{
"errorMessage": "ERROR_DELIVERY_OPTIONS_YOU_SELECTED_NOT_AVAILABLE_NOW",
"partNumbers":
[
19308033,
19114798
]
},
{
"errorMessage": "No Shipmodes Available for these orderItemsIds",
"orderItemIds": [
10315031,
10315032
]
}
]
【问题讨论】:
-
这是 JSON,所以试试
JSON.parse()
标签: javascript json parsing