本文介绍了将json解析为具有小写字段名称的数据结构的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在将JSON解析为ABAP结构,并且可以正常工作:

I am parsing JSON into ABAP structures, and it works:

DATA cl_oops TYPE REF TO cx_dynamic_check.
DATA(text) = `{"TEXT":"Hello ABAP, I'm JSON!","CODE":"123"}`.
TYPES: BEGIN OF ty_structure,
         text TYPE string,
         code TYPE char3,
       END OF ty_structure.
DATA : wa_structure TYPE ty_structure.
TRY.
    text = |\{"DATA":{ text }\}|.
    CALL TRANSFORMATION id OPTIONS clear = 'all'
         SOURCE XML text
         RESULT data = wa_structure.
    WRITE: wa_structure-text , wa_structure-code.
  CATCH cx_transformation_error INTO cl_oops.
    WRITE cl_oops->get_longtext( ).
ENDTRY.

有趣的部分是CODE和TEXT区分大小写.对于大多数外部系统,拥有所有CAPS标识符都很丑陋,因此我一直试图解析{"text":"Hello ABAP, I'm JSON!","code":"123"},但没有成功.我查看了选项,然后查看了更改后的id副本是否可以完成此操作,我在Google上进行了搜索,却不知道如何完成此操作.

The interesting part is that the CODE and TEXT are case sensitive. For most external systems, having all CAPS identifiers is ugly, so I have been trying to parse {"text":"Hello ABAP, I'm JSON!","code":"123"} without any success. I looked into the options, I looked whether a changed copy of id migh accomplish this, I googled it and have no idea how to accomplish this.

推荐答案

事实证明,SAP具有有关如何执行此操作的示例程序.基本上有一个现成的转换为您执行此操作,称为demo_json_xml_to_upper.这个名称有点不幸,所以我建议重命名此转换并将其添加到客户名称空间.

Turns out that SAP has a sample program on how to do this.There is basically an out of the box transformation that does this for you called demo_json_xml_to_upper. The name is a bit unfortunate, so I would suggest renaming this transformation and adding it to the customer namespace.

我有点沮丧,因为这只能通过xstrings起作用,因此调试它很麻烦.但是,它可以完美地解决了我的问题.

I am a bit bummed that this only works through xstrings, so debugging it becomes a pain. But, it works perfeclty and solved my problem.

这篇关于将json解析为具有小写字段名称的数据结构的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-03 06:38