SAP 内表数据转换为JSON格式

DATA: lv_json TYPE string.

DATA: lt_mapping_items TYPE /ui2/cl_json=>name_mappings.

DATA: BEGIN OF ls_detail,

code TYPE string,

name TYPE string,

age TYPE string,

END OF ls_detail,

lt_detail LIKE TABLE OF ls_detail,

BEGIN OF ls_header,

origh TYPE string,

orname TYPE string,

details LIKE lt_detail,

END OF ls_header.

ls_detail-code = 'A001'.

ls_detail-name = '张三'.

ls_detail-age = '18'.

APPEND ls_detail TO lt_detail.

ls_detail-code = 'A002'.

ls_detail-name = '李四'.

ls_detail-age = '25'.

APPEND ls_detail TO lt_detail.

ls_header-origh = 'C0001'.

ls_header-orname = '测试'.

ls_header-details = lt_detail.

"ABAP对应JSON字段映射

lt_mapping_items = VALUE #( ( abap = 'origh' json = 'orgid' )

( abap = 'orname' json = 'orname' )

( abap = 'details' json = 'details' )

( abap = 'code' json = 'id' )

( abap = 'name' json = 'name' )

( abap = 'age' json = 'age' )

).

"ABAP结构转JSON

lv_json = /ui2/cl_json=>serialize(

data = ls_header

compress = abap_false

pretty_name = /ui2/cl_json=>pretty_mode-camel_case

name_mappings = lt_mapping_items ).

WRITE: / 'ABAP转JSON结果:',lv_json.

相关推荐
ha_lydms3 小时前
MaxCompute中JSON函数
大数据·数据库·阿里云·json·dataworks·maxcompute·odps
LeoCrawls1 天前
Python 读取 JSON 常见报错排查,附完整处理函数
python·json·php
星河耀银海2 天前
数据解析:AI返回JSON数据在HTML5中的渲染方法
人工智能·json·html5
三8442 天前
Fastjson 漏洞 · 01 · 认识 Fastjson 与序列化基础
json·fastjson·反序列化
一直在努力的小宁2 天前
【阅读笔记】具身操作的数采方案概览
后端·json·restful·具身智能·vla·vlm
wuyk5552 天前
Python实战项目05:JSON数据解析与数据可视化小案例|全套实战闭环
python·信息可视化·json
波力海苔夹心脆6753 天前
C# 序列化与反序列化详解:System.Text.Json、Newtonsoft.Json、XmlSerializer 用法、特性选项与安全实践
经验分享·后端·c#·json·.net
snpgroupcn3 天前
跨国企业SAP升级解决方案(上篇):难点在哪,推广策略怎么定
sap
数据狐(Datafox)3 天前
淘宝商品详情API实战:多语言代购商城自动同步数据完整方案
开发语言·前端·数据库·爬虫·json
阿钱真强道4 天前
21 嵌入式操作系统 | JSON 与 json-c:生成与解析
c语言·开发语言·json·json-c