如何使用 Progress 4GL 从嵌套的 json“文件”中读取数据值

问题描述 投票:0回答:1

我将以下 JSON 结构存储在文件中,我想动态读取它并将值分配给临时表:

json

{ “转载”:{ "请求ID": "00000001", “设备代码”:“001”, “份数”:“2” } }

问题:直接使用 READ-JSON 无法按预期工作,可能是因为此 JSON 结构是嵌套的,而不是平面数组。

目标:我需要从嵌套结构中检索特定值,例如 DeviceCode。如何动态读取此 JSON 并将其值分配给我的临时表?

openedge progress-4gl
1个回答
0
投票

假设您使用的不是 Progress OpenEdge 的旧版本,您可以使用 Progress.Json.ObjectModel 类来解析您的文件。

ObjectModelParser 导入文件并将其转换为 JsonObject,然后提取内部“Reprint”对象并打印其属性:

using Progress.Json.ObjectModel.*.

def var oparser as ObjectModelParser no-undo.
def var ojson   as JsonObject no-undo.

oparser = new ObjectModelParser().

ojson = cast( oparser:ParseFile( 'file.json' ), JsonObject ).

ojson = ojson:getJsonObject( 'Reprint' ).

message
    ojson:getCharacter( 'RequestID' )
    ojson:getCharacter( 'DeviceCode' )
    ojson:getCharacter( 'Copies' )
    .

观看它飞行https://abldojo.services.progress.com/?shareId=66fc1475f3309a3dc1fbb038

© www.soinside.com 2019 - 2024. All rights reserved.