Difference between revisions of "SAP ABAP JSON"
From SapWiki
Line 1: | Line 1: | ||
==[[SAP_ABAP_JSON_XSLT|Ejemplo XSLT JSON]]== | ==[[SAP_ABAP_JSON_XSLT|Ejemplo XSLT JSON]]== | ||
+ | |||
+ | ==Uso en programas ABAP== | ||
+ | FORM crear_json USING p_guia TYPE zhr01_dgtl | ||
+ | p_uname | ||
+ | CHANGING p_string_json TYPE string. | ||
+ | DATA: json_writer TYPE REF TO cl_sxml_string_writer. | ||
+ | DATA json TYPE xstring. | ||
+ | DATA lt_guia TYPE TABLE OF zhr01_dgtl. | ||
+ | |||
+ | APPEND p_guia TO lt_guia. | ||
+ | |||
+ | json_writer = cl_sxml_string_writer=>create( | ||
+ | type = if_sxml=>co_xt_json ). | ||
+ | |||
+ | CALL TRANSFORMATION zhcm_guia_dgtl | ||
+ | SOURCE root = lt_guia | ||
+ | usuario = p_uname | ||
+ | RESULT XML json_writer. "se usa el ejemplo 2 de Ejemplos | ||
+ | |||
+ | json = json_writer->get_output( ). | ||
+ | |||
+ | * PERFORM encoding2 CHANGING json p_string_json. | ||
+ | PERFORM decode USING json | ||
+ | CHANGING p_string_json. | ||
+ | |||
+ | ENDFORM. " CREAR_JSON | ||
+ | |||
+ | FORM decode USING p_xstring | ||
+ | CHANGING p_string. | ||
+ | |||
+ | CALL METHOD cl_http_utility=>if_http_utility~decode_utf8 | ||
+ | EXPORTING | ||
+ | encoded = p_xstring | ||
+ | RECEIVING | ||
+ | unencoded = p_string. | ||
+ | |||
+ | ENDFORM. "decode | ||
[[:Categoría:ABAP]] | [[:Categoría:ABAP]] |
Revision as of 13:33, 26 March 2020
Ejemplo XSLT JSON
Uso en programas ABAP
FORM crear_json USING p_guia TYPE zhr01_dgtl p_uname CHANGING p_string_json TYPE string. DATA: json_writer TYPE REF TO cl_sxml_string_writer. DATA json TYPE xstring. DATA lt_guia TYPE TABLE OF zhr01_dgtl. APPEND p_guia TO lt_guia. json_writer = cl_sxml_string_writer=>create( type = if_sxml=>co_xt_json ). CALL TRANSFORMATION zhcm_guia_dgtl SOURCE root = lt_guia usuario = p_uname RESULT XML json_writer. "se usa el ejemplo 2 de Ejemplos json = json_writer->get_output( ). * PERFORM encoding2 CHANGING json p_string_json. PERFORM decode USING json CHANGING p_string_json. ENDFORM. " CREAR_JSON
FORM decode USING p_xstring CHANGING p_string. CALL METHOD cl_http_utility=>if_http_utility~decode_utf8 EXPORTING encoded = p_xstring RECEIVING unencoded = p_string. ENDFORM. "decode