Variante 1 (/ui2/cl_json)
* ABAP Zieldatentyp
TYPES: BEGIN OF ty_abap,
param1 TYPE char64,
param2 TYPE char64,
END OF ty_abap.
* JSON-Quelldaten
DATA: lv_json_response TYPE string VALUE '{"param1":123,"param2":321}'.
DATA: ls_abap TYPE ty_abap.
TRY.
* JSON->ABAP
/ui2/cl_json=>deserialize( EXPORTING json = lv_json_response
pretty_name = /ui2/cl_json=>pretty_mode-camel_case
CHANGING data = ls_abap ).
cl_demo_output=>write_data( lv_json_response ).
cl_demo_output=>write_data( ls_abap ).
cl_demo_output=>display( ).
CATCH cx_root INTO DATA(e_txt).
MESSAGE e_txt->get_text( ) TYPE 'S' DISPLAY LIKE 'E'.
ENDTRY.
Variante 2 (cl_fdt_json)
* ABAP Zieldatentyp
TYPES: BEGIN OF ty_abap,
success TYPE string,
msg TYPE string,
matnr TYPE matnr,
END OF ty_abap.
* JSON-Quelldaten
DATA: lv_json_response TYPE string VALUE '{"success":true,"msg":"Ok.","matnr":0000001234}'.
DATA: ls_abap TYPE ty_abap.
cl_fdt_json=>json_to_data( EXPORTING iv_json = lv_json_response
CHANGING ca_data = ls_abap ).
cl_demo_output=>write_data( lv_json_response ).
cl_demo_output=>write_data( ls_abap ).
cl_demo_output=>display( ).
VAriante 3 (cl_clb_parse_json)
* ABAP Zieldatentyp
TYPES: BEGIN OF ty_abap,
success TYPE string,
msg TYPE string,
matnr TYPE matnr,
END OF ty_abap.
TRY.
* JSON-Quelldaten
DATA(lv_json_response) = CONV string( '{"success":"true","msg":"Ok.","matnr":"0000001234"}' ).
* JSON nach XSTRING (UTF-8) konvertieren
DATA(lvx_string) = cl_abap_codepage=>convert_to( lv_json_response ).
* XSTRING nach string wandeln
DATA(lv_utf8) = cl_clb_tools=>xstring_to_string( lvx_string ).
* JSON->ABAP
DATA(o_json) = NEW cl_clb_parse_json( ).
DATA: ls_abap TYPE ty_abap.
o_json->json_to_data( EXPORTING iv_json = lv_utf8
CHANGING c_data = ls_abap ).
cl_demo_output=>write_data( lv_json_response ).
cl_demo_output=>write_data( ls_abap ).
cl_demo_output=>display( ).
CATCH cx_root INTO DATA(e_txt).
MESSAGE e_txt->get_text( ) TYPE 'S' DISPLAY LIKE 'E'.
ENDTRY.