JSON 使用什么类型:string 还是 xstring?

What type to use for JSON: string or xstring?

我使用 ABAP 方法创建 JSON。

例如:

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 ).

我应该为 json 使用哪种数据类型?

使用string还是xstring?

根据此博客条目(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" 因此我会使用 xstring。

没有"good way"。每个解决方案都有优点和缺点。

如果您的数据主要包含 "latin" 个字符,则使用 xstring 和 UTF-8 编码,它会占用更少的内存。

  • xstring 使用 UTF-8 编码:一个字节用于普通 A-Z/a-z/0-9 字符,两个字节用于重音字符,更多字节用于其他语言(中文等)的字符。
  • string:每个字符两个字节(编码类似于 UCS-2),因为所有 ABAP 系统现在都是 Unicode (ABAP >= 7.50)。