JSON 使用什么类型:string 或 xstring? [英] What type to use for JSON: string or xstring?

查看:38
本文介绍了JSON 使用什么类型:string 或 xstring?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用 ABAP 方法创建 JSON.

I create JSON with ABAP methods.

例如:

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 使用哪种数据类型?

Which data type should I use for json?

使用string还是xstring?

推荐答案

没有好方法".每种解决方案都有优点和缺点.

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

如果你的数据主要包含拉丁"字符,那么使用xstring和UTF-8编码,它会占用更少的内存.

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

  • xstring UTF-8 编码:1 个字节用于普通 AZ/az/0-9 字符,2 个字节用于重音字符,更多字节用于其他语言(中文等)字符.
  • string:每个字符两个字节(编码类似于 UCS-2),因为所有 ABAP 系统现在都是 Unicode (ABAP >= 7.50).
  • 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).

这篇关于JSON 使用什么类型:string 或 xstring?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆