What type to use for JSON: string or xstring?

陌路散爱 提交于 2020-03-26 05:48:08

问题


I create JSON with abap methods.

For example:

DATA(lo_json_writer) = cl_sxml_string_writer=>create( type = if_sxml=>co_xt_json ).
CALL TRANSFORMATION id
        SOURCE result = result
        RESULT XML lo_json_writer.

cl_abap_conv_in_ce=>create( )->convert(
        EXPORTING
          input = lo_json_writer->get_output( )
        IMPORTING
          data = json ).

Which data type should I use for json?

Use string or xstring?


回答1:


There's no "good way". Each solution has advantages and drawbacks.

If your data contains mostly "latin" characters, then use xstring with UTF-8 encoding, it will occupy less memory.

  • xstring with UTF-8 encoding: one byte for common A-Z/a-z/0-9 characters, two bytes for accentuated characters, and more bytes for characters from other languages (Chinese and so on).
  • string: two bytes per character (encoding is like UCS-2), since all ABAP systems are now Unicode (ABAP >= 7.50).



回答2:


According to this blog-entry(https://blogs.sap.com/2013/01/07/abap-and-json/): "For storing XML data in strings or internal tables, we recommend that you use byte strings or byte-like line types" Therefore i would use xstring.



来源:https://stackoverflow.com/questions/55900518/what-type-to-use-for-json-string-or-xstring

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!