简体   繁体   English

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

[英]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.

相关问题 将 JSON xstring 反序列化为 ABAP 中的结构 - Deserializing JSON xstring to structure in ABAP 用于JSON Web加密的MIME类型是什么 - What is the mime type to use for JSON Web Encryption JSON对象数组使用什么类型? - What type to use for an array of JSON objects? 哪种数据类型应该正确才能将JSON内容存储为字符串? - What data type should be correct to store JSON content as string? 反序列化JSON字符串时如何知道将JObject转换为哪种类型 - How to know what type to cast a JObject to when deserializing a JSON string 我应该使用哪种类型的使用Volley进行JSON解析? - What type of JSON parsing using volley I should use? 使用JSON模式获取特定类型的所有值(HTML字符串) - Use JSON Schema to get all values of a certain type (HTML string) fluentd 中的“type json”和“parse json”有什么区别,我应该使用什么? - What's the difference between "type json" and "parse json" in fluentd and what should I use? 我可以控制反序列化JSON字符串时要使用的子类型吗? - Can I control what subtype to use when deserializing a JSON string? Rust 使用 Postgres JSON 属性:不能在 Rust 类型 `alloc::string::String` 和 Postgres 类型 `jsonb 之间转换 - Rust use Postgres JSON attribute: cannot convert between the Rust type `alloc::string::String` and the Postgres type `jsonb`
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM