(Help) Make a list - REST

Posted by rubiaoliveira on 01-Dec-2018 18:14

How can I post the ITEMS list like the example os Json's code?

The first block is OK:

oJson = new JsonObject().
oJson:Add('appId', 'totvs.1').
oJson:Add('token', '').
oJson:Add('activityId', '1').
oJson:Add('IdCode', '55-0438736-1056435-3102D').

{
  "appId" : "totvs.1",
  "token" : "",
  "activityId" : 1,
  "idcode" : "55-0438736-1056435-3102D",
  "items" : [ {
    "material" : {
      "id" : "00930",
      "name" : "CONSERVANTE MONOCÁLCIO",
      "desc1" : "CONSERVAR EM TEMPERATURA ATÉ 20 oC",
    },
    "itemIdx" : 1,
    "itemSupBatch" : "BA-23903",
    "itemErpBatch" : null,
  }, {
    "material" : {
      "id" : "00930",
      "name" : "CONSERVANTE MONOCÁLCIO",
      "desc1" : "CONSERVAR EM TEMPERATURA ATÉ 20 oC",
    },
    "itemIdx" : 2,
    "itemSupBatch" : "BA-23904",
    "itemErpBatch" : null,
  } ]
}

Posted by Ruben Dröge on 03-Dec-2018 07:58

using Progress.Json.ObjectModel.*.

define variable oJson   as JsonObject.
define variable oJson2  as JsonObject.
define variable oJson3  as JsonObject.
define variable aJson   as JsonArray.

oJson   = new JsonObject().
oJson2  = new JsonObject().
oJson3  = new JsonObject().
aJson   = new JsonArray().

oJson:Add('appId', 'totvs.1').
oJson:Add('token', '').
oJson:Add('activityId', '1').
oJson:Add('IdCode', '55-0438736-1056435-3102D').
oJson2:Add('material', oJson3).
oJson2:ADD('itemIdx', 1).
oJson2:ADD('itemSupBatch', 1).
oJson2:ADD('itemErpBatch', 1).
oJson3:Add('id', '00930').
oJson3:Add('name', 'CONSERVANTE MONOCALCIO').
oJson:Add('items', aJson).
aJson:Add(0, oJson2).
aJson:Add(1, oJson3).

oJson:WriteFile('c:\temp\oJson.json', true).

All Replies

Posted by goo on 02-Dec-2018 19:28

Look at jsonArray, add oJson to that....

Posted by rubiaoliveira on 03-Dec-2018 00:57

Did you have an example?

Posted by Ruben Dröge on 03-Dec-2018 07:58

using Progress.Json.ObjectModel.*.

define variable oJson   as JsonObject.
define variable oJson2  as JsonObject.
define variable oJson3  as JsonObject.
define variable aJson   as JsonArray.

oJson   = new JsonObject().
oJson2  = new JsonObject().
oJson3  = new JsonObject().
aJson   = new JsonArray().

oJson:Add('appId', 'totvs.1').
oJson:Add('token', '').
oJson:Add('activityId', '1').
oJson:Add('IdCode', '55-0438736-1056435-3102D').
oJson2:Add('material', oJson3).
oJson2:ADD('itemIdx', 1).
oJson2:ADD('itemSupBatch', 1).
oJson2:ADD('itemErpBatch', 1).
oJson3:Add('id', '00930').
oJson3:Add('name', 'CONSERVANTE MONOCALCIO').
oJson:Add('items', aJson).
aJson:Add(0, oJson2).
aJson:Add(1, oJson3).

oJson:WriteFile('c:\temp\oJson.json', true).

This thread is closed