ABAP json与内容及类型的转换

LV_JSON = '{"BUKRS":1000,"SWERKS":[{"SIGN":"I","OPTION":"EQ","LOW":1000,"HIGH":2100},{"SIGN":"I","OPTION":"EQ","LOW":"1000","HIGH":"2100"}]}'.
"注意大写 
DATA:lwwerks TYPE BAPI_ITOB_SEL_DESCRIPT.
DATA:ltwerks LIKE STANDARD TABLE OF lwwerks.
data:bukrs TYPE t001-bukrs.
CALL TRANSFORMATION ID
SOURCE XML lv_json
RESULT
BUKRS = BUKRS   "注意大写
SWERKS = LTWERKS[].  "注意大写

PS:如果是日期格式的,在json中还是要用 YYYY-MM-DD 格式,abap会自己转换成YYYYMMDD

以上是json转 对象

以下是对象转json

"  abap 转json
data: json_writer TYPE REF TO cl_sxml_string_writer.
json_writer = cl_sxml_string_writer=>create( TYPE = if_sxml=>co_xt_json ).
CALL TRANSFORMATION ID
SOURCE content = lv_em
itable  = lt_but021
RESULT XML json_writer.
data: json TYPE ETXML_LINE_STR.
json = json_writer->get_output( ).
DATA: lv_json TYPE string .
CALL FUNCTION 'ECATT_CONV_XSTRING_TO_STRING'
EXPORTING
  im_xstring  = json
  im_encoding = 'UTF-8'
IMPORTING
  ex_string   = lv_json.

你可能感兴趣的:(ABAP,json)