好男人就是我,我就是你兵哥
分类: IT职场
2015-08-04 16:22:30
DATA lv_json TYPE string."定义JSON存放的变量
DATA lr_json_serializer TYPE REF TO cl_trex_json_serializer."解析JSON 用到的类(编译成JSON格式)
DATA lr_json_deserializer TYPE REF TO cl_trex_json_deserializer. "解析JSON 用到的类(解析JSON格式)
DATA: BEGIN OF wa_wl,
zzfld0000ht TYPE crmt_item_descr_partner,
zzfld0000hu TYPE crmt_prshtextx_db,
zzfld0000hv TYPE zdtel00002x,
zzfld0000hw TYPE zdtel000135,
zzfld0000hx TYPE zdtel0001d3,
zzfld0000i0 TYPE char10,
END OF wa_wl.
"根据结构通过这个类可以转换成JSON格式
CREATE OBJECT lr_json_serializer
EXPORTING
data = wa_wl.
lr_json_serializer->serialize( ).
lv_json = lr_json_serializer->get_data( ).
"OA 需要用双引号才能识别是JSON格式这里需要转换下
REPLACE 'zzfld0000i0'IN lv_json WITH '"ZCBZ"'.
REPLACE 'zzfld0000ht'IN lv_json WITH '"WLBM"'.
REPLACE 'zzfld0000hu'IN lv_json WITH '"WLMC"'.
REPLACE 'zzfld0000hw'IN lv_json WITH '"WLDJ"'.
REPLACE 'zzfld0000hv'IN lv_json WITH '"WLSL"'.
REPLACE 'zzfld0000hx'IN lv_json WITH '"HJ"'.
IF i_num > 1.
CONCATENATE str1 ',' INTO str1.
ENDIF.
CONCATENATE str1 lv_json INTO str1.
IF str1 IS NOT INITIAL.
CONCATENATE '[' str1 ']' INTO str1.
CONDENSE str1 NO-GAPS.
set_fieldcat 'RTFTEXTDYNAMIC' str1.
ENDIF.