本帖最后由 amtath 于 2023-8-15 23:57 编辑
有时候,我们调用api做数据对接,传json时会有格式要求。例如:
说明文档:https://open.chanjet.com/docs/fi ... d/t+dj/xhd?id=30787
当我们把这一串复制到http请求命令中之后,对应的表体参数这里直接静态了。orz。咋整,我们的表体可肯定不会永远只有一行
半路出家,卡这个问题好久了。终于有一天,电闪雷鸣,我顿悟了,那是不可能的,查论坛资料,听说可以构造。
于是,叮叮咚咚一翻,捣鼓出来了:结合我们的对象操作和集合操作命令。
执行过程如下:
- 创建数组对象: array 用时:0毫秒。
- 创建变量 array = []
- 设置变量命令 : entrys 用时:4毫秒。
- SELECT [ID], [item], [qty], [warehouse], [amount], [fbatchno] FROM 表1
- 创建变量 entrys = [{"ID":1,"item":"aa","qty":"100","warehouse":"a","amount":"1000","fbatchno":"11"},{"ID":2,"item":"bb","qty":"200","warehouse":"b","amount":"2000","fbatchno":"22"},{"ID":3,"item":"cc","qty":"50","warehouse":"a","amount":"500","fbatchno":"333"}]
- 循环命令 用时:1毫秒。
- 创建变量 entry = {"ID":1,"item":"aa","qty":"100","warehouse":"a","amount":"1000","fbatchno":"11"}
- 创建对象: bankobject 用时:0毫秒。
- 创建变量 bankobject = {}
- 创建对象: Inventory 用时:0毫秒。
- 创建变量 Inventory = {"Code":"aa"}
- 创建对象: Warehouse 用时:0毫秒。
- 创建变量 Warehouse = {"Code":"a"}
- 对象操作(SetProperties):fullobject 用时:0毫秒。
- 创建变量 fullobject = {"Inventory":{"Code":"aa"},"Warehouse":{"Code":"a"},"Batchno":"11","Qty":"100","Amount":"1000"}
- 追加数组项目到已有数组: array 用时:0毫秒。
- 设置变量 array = [{"Inventory":{"Code":"aa"},"Warehouse":{"Code":"a"},"Batchno":"11","Qty":"100","Amount":"1000"}]
- 设置变量 entry = {"ID":2,"item":"bb","qty":"200","warehouse":"b","amount":"2000","fbatchno":"22"}
- 创建对象: bankobject 用时:0毫秒。
- 设置变量 bankobject = {}
- 创建对象: Inventory 用时:0毫秒。
- 设置变量 Inventory = {"Code":"bb"}
- 创建对象: Warehouse 用时:0毫秒。
- 设置变量 Warehouse = {"Code":"b"}
- 对象操作(SetProperties):fullobject 用时:0毫秒。
- 设置变量 fullobject = {"Inventory":{"Code":"bb"},"Warehouse":{"Code":"b"},"Batchno":"22","Qty":"200","Amount":"2000"}
- 追加数组项目到已有数组: array 用时:0毫秒。
- 设置变量 array = [{"Inventory":{"Code":"aa"},"Warehouse":{"Code":"a"},"Batchno":"11","Qty":"100","Amount":"1000"},{"Inventory":{"Code":"bb"},"Warehouse":{"Code":"b"},"Batchno":"22","Qty":"200","Amount":"2000"}]
- 设置变量 entry = {"ID":3,"item":"cc","qty":"50","warehouse":"a","amount":"500","fbatchno":"333"}
- 创建对象: bankobject 用时:0毫秒。
- 设置变量 bankobject = {}
- 创建对象: Inventory 用时:0毫秒。
- 设置变量 Inventory = {"Code":"cc"}
- 创建对象: Warehouse 用时:0毫秒。
- 设置变量 Warehouse = {"Code":"a"}
- 对象操作(SetProperties):fullobject 用时:0毫秒。
- 设置变量 fullobject = {"Inventory":{"Code":"cc"},"Warehouse":{"Code":"a"},"Batchno":"333","Qty":"50","Amount":"500"}
- 追加数组项目到已有数组: array 用时:0毫秒。
- 设置变量 array = [{"Inventory":{"Code":"aa"},"Warehouse":{"Code":"a"},"Batchno":"11","Qty":"100","Amount":"1000"},{"Inventory":{"Code":"bb"},"Warehouse":{"Code":"b"},"Batchno":"22","Qty":"200","Amount":"2000"},{"Inventory":{"Code":"cc"},"Warehouse":{"Code":"a"},"Batchno":"333","Qty":"50","Amount":"500"}]
- 创建对象: Dto 用时:0毫秒。
- 创建变量 Dto = {"Dto":[{"Inventory":{"Code":"aa"},"Warehouse":{"Code":"a"},"Batchno":"11","Qty":"100","Amount":"1000"},{"Inventory":{"Code":"bb"},"Warehouse":{"Code":"b"},"Batchno":"22","Qty":"200","Amount":"2000"},{"Inventory":{"Code":"cc"},"Warehouse":{"Code":"a"},"Batchno":"333","Qty":"50","Amount":"500"}]}
- 返回命令 用时:0毫秒。
- 错误码: 0
- 信息: {"Dto":[{"Inventory":{"Code":"aa"},"Warehouse":{"Code":"a"},"Batchno":"11","Qty":"100","Amount":"1000"},{"Inventory":{"Code":"bb"},"Warehouse":{"Code":"b"},"Batchno":"22","Qty":"200","Amount":"2000"},{"Inventory":{"Code":"cc"},"Warehouse":{"Code":"a"},"Batchno":"333","Qty":"50","Amount":"500"}]}
- '服务端命令1'命令执行结束, 用时:22毫秒。
复制代码 最后,再调用http请求的时候,把静态的参数,改成我们构造好的数组对象传进去。
附上工程,方便跟我一样想不开的格友参考。
构造数组对象.fgcc
(418.21 KB, 下载次数: 451)
|