从ABAP到JSON

2020-09-08 08:22发布

         点击此处--->   EasySAP.com群内免费提供SAP练习系统(在群公告中)

加入QQ群:457200227(SAP S4 HANA技术交流) 群内免费提供SAP练习系统(在群公告中)


您好,我正在尝试转换一个由我自己填写的内部表,该表基于我创建的许多结构和深层结构(SE11)。

阅读此书: https://wiki.scn.sap.com/wiki/display/Snippets/One+more+ABAP+to+JSON+Serializer+and+Deserializer

并使用它:

 LV_JSON =/UI2/CL_JSON => SERIALIZE(DATA = it_main_tb COMPRESS = ABAP_TRUE pretty_name =/ui2/cl_json => pretty_mode-camel_case)。

但不使用camelCase格式化

 lv_json = [{" businesspartnercategory":" 2"," businesspartnergrouping":" ZNAC"," organizationbpname1":"RAZÓNSOCIAL"," organizationbpname2":" A"," organizationbpname3":" B"," organizationbpname4  ":" C"," toBusinesspartneraddress":{" cityname":" SANTIAGO"," country":" CL"," district" ... 

我需要这样:

 {
   " d":{
     " BusinessPartnerCategory":" 2",
     " BusinessPartnerGrouping":" ZNAC",
     " OrganizationBPName1":" RAZON SOCIAL",
     " OrganizationBPName2":" A",
     " OrganizationBPName3":" B",
     " OrganizationBPName4":" C",
     " SearchTerm1":"",
     " to_BusinessPartnerAddress":{
       "结果":[
         {
           " CityName":" SANTIAGO",
           " Country":" CL",
           "区":" 02",
           "语言":" ES",
           "邮政编码":" 8320000",
           " StreetName":" HOLANDA 99",
           " to_EmailAddress":{
             "结果":[
               {
                 " EmailAddress":" email@email.com"
               }
             ]
           }
         }
       ]
     },
 

因此所有" _"都将被删除,并且无法使用cameCase格式化

我的课堂通话怎么了? 有什么想法吗?

         点击此处--->   EasySAP.com群内免费提供SAP练习系统(在群公告中)

加入QQ群:457200227(SAP S4 HANA技术交流) 群内免费提供SAP练习系统(在群公告中)


您好,我正在尝试转换一个由我自己填写的内部表,该表基于我创建的许多结构和深层结构(SE11)。

阅读此书: https://wiki.scn.sap.com/wiki/display/Snippets/One+more+ABAP+to+JSON+Serializer+and+Deserializer

并使用它:

 LV_JSON =/UI2/CL_JSON => SERIALIZE(DATA = it_main_tb COMPRESS = ABAP_TRUE pretty_name =/ui2/cl_json => pretty_mode-camel_case)。

但不使用camelCase格式化

 lv_json = [{" businesspartnercategory":" 2"," businesspartnergrouping":" ZNAC"," organizationbpname1":"RAZÓNSOCIAL"," organizationbpname2":" A"," organizationbpname3":" B"," organizationbpname4  ":" C"," toBusinesspartneraddress":{" cityname":" SANTIAGO"," country":" CL"," district" ... 

我需要这样:

 {
   " d":{
     " BusinessPartnerCategory":" 2",
     " BusinessPartnerGrouping":" ZNAC",
     " OrganizationBPName1":" RAZON SOCIAL",
     " OrganizationBPName2":" A",
     " OrganizationBPName3":" B",
     " OrganizationBPName4":" C",
     " SearchTerm1":"",
     " to_BusinessPartnerAddress":{
       "结果":[
         {
           " CityName":" SANTIAGO",
           " Country":" CL",
           "区":" 02",
           "语言":" ES",
           "邮政编码":" 8320000",
           " StreetName":" HOLANDA 99",
           " to_EmailAddress":{
             "结果":[
               {
                 " EmailAddress":" email@email.com"
               }
             ]
           }
         }
       ]
     },
 

因此所有" _"都将被删除,并且无法使用cameCase格式化

我的课堂通话怎么了? 有什么想法吗?

付费偷看设置
发送
3条回答
95年老男孩
1楼-- · 2020-09-08 08:41

您在SE11结构中是否具有带下划线的字段名称?
像这样:business_partner_category = businessPartnerCategory

否则,您的代码看起来还可以。 因此,如果您的字段名称正确(带有下划线),则可能需要更新/UI2/CL_JSON。 我认为您有一些带有错误的旧版本。 有SAP NOTES进行了更新...
我们经常使用此类,它非常有用并且非常有用。
编辑:请注意,对于首字母大写,您需要以下划线开头的字段名称:
_test_field_name(字段名称)= TestFieldName(JSON中)

歪着头看世界
2楼-- · 2020-09-08 08:49

是 我注意到我要在大写字母前加一个下划线,但谢谢! :D问题是我的字段名称太长,但是我用替换全部解决了问题

槿木_熙
3楼-- · 2020-09-08 08:49

这可能很明显,但是在最坏的情况下,您可以使用Concatenate构建JSON文本 (或方括号); 保留您想要的任何大小写规则。 如果您选择此路径,则此处的代码库可能会对您有所帮助: https: //github.com/keremkoseoglu/ABAP-Library/blob/master/zcl_bc_json_toolkit.abap

一周热门 更多>