[英]What type to use for JSON: string or xstring?
I create JSON with ABAP methods.我使用 ABAP 方法创建 JSON。
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?我应该为 json 使用哪种数据类型?
Use string
or xstring
?使用string
还是xstring
?
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.如果你的数据主要包含“拉丁”字符,那么使用UTF-8编码的xstring
,它会占用更少的内存。
xstring
with UTF-8 encoding: one byte for common AZ/az/0-9 characters, two bytes for accentuated characters, and more bytes for characters from other languages (Chinese and so on).使用 UTF-8 编码的xstring
:一个字节用于常见的 AZ/az/0-9 字符,两个字节用于重音字符,更多字节用于来自其他语言(中文等)的字符。string
: two bytes per character (encoding is like UCS-2
), since all ABAP systems are now Unicode (ABAP >= 7.50). string
:每个字符两个字节(编码类似于UCS-2
),因为所有 ABAP 系统现在都是 Unicode (ABAP >= 7.50)。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://blogs.sap.com/2013/01/07/abap-and-json/ ):“为了将 XML 数据存储在字符串或内部表中,我们建议您使用字节字符串或类似字节的行类型”因此我会使用 xstring。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.