我收到如下 JSON 响应
[ { “状态”:“00” }, { “订单到期日期”:“”, “客户地址”:“”, "消费者ID": "", “支付的金额”: ””, “创建日期”: ””, "客户邮箱": "", "交易状态": "", “付款日期”:“”, “总处罚”:“”, "订单ID": "", “付款方式”: ””, “ID”: ””, “签发日期”: ””, “客户手机”:“”, “订单金额”: ”” } ]
可以看到,字段名称中有空格。我通过
/ui2/cl_json=>deserialize
将其反序列化到下表中,但由于字段名称中的空格而没有发生。
TYPES: BEGIN OF ty_data,
Id TYPE string,
"Order Due Date" TYPE string, "invalid ABAP syntax, commented
OrderDueDate TYPE string, "correct
fld3 TYPE string,
fld4 TYPE string,
fld5 TYPE string,
fld6 TYPE string,
fld7 TYPE string,
fld8 TYPE string,
fld9 TYPE string,
fld10 TYPE string,
fld11 TYPE string,
fld12 TYPE string,
fld13 TYPE string,
fld14 TYPE string,
fld15 TYPE string,
END OF ty_data.
请帮忙。我正在使用ABAP 7.5。
必须映射字段名称。这可以通过使用方法的 name_mapping 参数来实现。
JSON:订单到期日期
ABAP:ORDER_DUE_DATE
映射:
DATA( lt_name_mappings ) = VALUE /ui2/cl_json=>name_mappings( ( abap = 'ORDER_DUE_DATE'
json = 'Order Due Date' ) ). "This for all fields to be mapped
CALL METHOD /ui2/cl_json=>deserialize
EXPORTING
json = json_file
* jsonx =
* pretty_name = PRETTY_MODE-NONE
* assoc_arrays = C_BOOL-FALSE
* assoc_arrays_opt = C_BOOL-FALSE
name_mappings = lt_name_mappings
* conversion_exits = C_BOOL-FALSE
* hex_as_base64 = C_BOOL-TRUE
CHANGING
data = ls_data.