
data serializer type ref to cl_trex_json_serializer.
types: begin of type_s1,
key type string,
value type string,
end of type_s1.
data lt_json type table of type_s1.
data ls_json type type_s1.
ls_json-key = 'country'.
ls_json-value = 'cn'.
APPEND ls_json to lt_json.
ls_json-key = 'QA'.
ls_json-value = '1000'.
APPEND ls_json to lt_json.
ls_json-key = 'BS'.
ls_json-value = '2000'.
APPEND ls_json to lt_json.
ls_json-key = 'PS'.
ls_json-value = '3000'.
APPEND ls_json to lt_json.
ls_json-key = 'GA'.
ls_json-value = '4000'.
APPEND ls_json to lt_json.
create object serializer
exporting
data = lt_json.
serializer->serialize( ).
write: / serializer->get_data( ).
---------2021.9.14---------------
上面的JSON并不标准,字段名称没有使用双引号
需要换成下面这个:
"3、产生JSON
data serializer type ref to cl_trex_json_serializer.
types: begin of type_s1,
item type string,
end of type_s1.
data lt_json type table of type_s1.
data ls_json type type_s1.
ls_json-item = lv_QUANT.
APPEND ls_json to lt_json.
ls_json-item = ls_ord_rfc_jiaoyan-COUNTRY.
APPEND ls_json to lt_json.
ls_ord_rfc_jiaoyan-COUNTRY = /ui2/cl_json=>serialize( data = lt_json compress = abap_true pretty_name = /ui2/cl_json=>pretty_mode-camel_case ).
产生的JSON文本:
[{"item":"31.000 "},{}]
该博客讲述了如何将不标准的JSON转换为标准格式,涉及 dataserializertypereftocl_trex_json_serializer 类型和操作,如序列化、调整键值对并创建对象。重点在于处理键未加引号的问题和使用Abap技术生成特定格式的JSON。
4738

被折叠的 条评论
为什么被折叠?



