json字符串内容
{
"I_INT_NAME":"Z_TEST_FUNCTION",
"I_KEY":"123456",
"I_JSON":{
"AUFNR":"0000123456"
}
}
用notepad++插件中的Base64 Encode功能转码
转码结果:
eyJJX0lOVF9OQU1FIjoiWl9URVNUX0ZVTkNUSU9OIiwiSV9LRVkiOiIxMjM0NTYiLCJJX0pTT04iOnsiQVVGTlIiOiIwMDAwMTIzNDU2In19
abap程序代码:
DATA input TYPE string VALUE 'eyJJX0lOVF9OQU1FIjoiWl9URVNUX0ZVTkNUSU9OIiwiSV9LRVkiOiIxMjM0NTYiLCJJX0pTT04iOnsiQVVGTlIiOiIwMDAwMTIzNDU2In19'.
DATA output TYPE xstring.
DATA result TYPE string.
DATA convin TYPE REF TO cl_abap_conv_in_ce.
"Convert Base64 string to Xstring
CALL FUNCTION 'SCMS_BASE64_DECODE_STR'
EXPORTING
input = input
IMPORTING
output = output
EXCEPTIONS
failed = 1
OTHERS = 2.
IF sy-subrc <> 0.
* Implement suitable error handling here
ENDIF.
"transform the Xstring to Binary
convin = cl_abap_conv_in_ce=>create( input = output ).
"turn the Binary format to String
convin->read( IMPORTING data = result ).
cl_demo_output=>display( result ).
测试结果:
原创文章,作者:ItWorker,如若转载,请注明出处:https://blog.ytso.com/17872.html