内表:
A | B | C |
IMINGZHA | HAIMINGZ |
AIMINGZH |
1 | 2 |
3 |
4 | 5 |
6 |
Json串: [{a: "IMINGZHA", b: "HAIMINGZ", c: "AIMINGZH"}, {a: "1", b: "2", c: "3"}, {a: "4", b: "5", c: "6"}]
DATA: json_ser TYPE REF TO CL_TREX_JSON_SERIALIZER,
json_des TYPE REF TO CL_TREX_JSON_DESERIALIZER.
DATA: jsonstr TYPE string. DATA: BEGIN OF IT_TAB OCCURS ,
A TYPE CHAR10,
B TYPE CHAR10,
C TYPE CHAR10,
END OF IT_TAB. IT_TAB-A = 'IMINGZHA' .
IT_TAB-B = 'HAIMINGZ' .
IT_TAB-C = 'AIMINGZH' .
APPEND IT_TAB. IT_TAB-A = '' .
IT_TAB-B = '' .
IT_TAB-C = '' .
APPEND IT_TAB. IT_TAB-A = '' .
IT_TAB-B = '' .
IT_TAB-C = '' .
APPEND IT_TAB. *内表 转 Json 串
CREATE OBJECT json_ser
EXPORTING
data = IT_TAB[].
CALL METHOD json_ser->SERIALIZE.
CALL METHOD json_ser->GET_DATA
RECEIVING
rval = jsonstr. BREAK-POINT.
*Json 串 append 内表
CREATE OBJECT json_des.
CALL METHOD json_des->DESERIALIZE
EXPORTING
json = jsonstr
IMPORTING
abap = IT_TAB[]. BREAK-POINT.