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.

相关推荐
麻瓜code1 天前
流式返回的工具参数是一段一段来的,怎么拼成一个 JSON
json
鲸渔3 天前
【AI Agent系列课程13-Python 基础13】JSON 读写:结构化数据交换基础
开发语言·python·json·ai编程
aiotto资源分享6 天前
Python 写 JSON 文件,程序中途退出会留下什么?
java·python·json·jsondecodeerror
一起学安全技术7 天前
拆大模型 10|结构化输出:让模型返回数据,而不是一段话
人工智能·语言模型·json
用户298698530147 天前
在 Python 中把 Word 文档转换为 JSON 的三种实现方式
python·json·api
FRing039 天前
vue2干货总结10(json-server、vant-ui、postcss插件、axios二次封装、图形验证码、toast轻提示)
开发语言·前端·vue.js·ui·json·vue2·postcss
用户298698530149 天前
使用 Python 将 JSON 转换为 Word 文档的实践指南
python·json·api
九英里路9 天前
protobuf快速上手
网络·c++·中间件·json·谷歌·序列化·protobuf
wuyk55510 天前
Spider-第09讲-三格式落盘CSV-Excel-JSON
爬虫·python·json·excel
wuyk55511 天前
Spider-第07讲-JSON接口与正则提取
爬虫·python·json