jerrygjj
8th August 2022, 17:59
Below is my Json result. How to get "nameA" and "nameB" information. I can't find out the example at progguide_10.7.4_en.chm. Thank
---------------------------------------------------------------------------------------------
{
"data": [{
"name": "nameA",
"shortName": nameA,
"code": "A001"},
{
"name": "nameB",
"shortName": "nameB",
"code": "A002"
}
],
"code": "200",
"message": null
}

jerrygjj
9th August 2022, 02:18
I can used Json.getString funcation got code number is 200. but I try to used Json.getString got "name" show can not continue. I'm not sure which function I can got the "name". thanks.
-----------------------------------------------------------------------------
below is my some script
jsonvalue= Json.read(bodystream, errormsg, JSON_READ_UTF8)
department_code = Json.getString(jsonvalue,"code") |* Just got the level top code 200
"savename"= Json.getString(Json.get(jsonvalue, "data"), "name") |* error can not continue

vamsi_gujjula
9th August 2022, 19:10
{
"orders":[{
"downTime": [
{
"time": 2696,
"t1": 1,
"t2": 0,
"t3": 0
},
{
"time": 236,
"t1": 10,
"t2": 7,
"t3": 0
},
{
"time": 197,
"t1": 8,
"t2": 3,
"t3": 0
},
{
"time": 56,
"t1": 6,
"t2": 6,
"t3": 0
},
{
"time": 47,
"t1": 6,
"t2": 6,
"t3": 0
},
{
"time": 21,
"t1": 6,
"t2": 6,
"t3": 0
},
{
"time": 26,
"t1": 10,
"t2": 7,
"t3": 0
},
{
"time": 26,
"t1": 10,
"t2": 7,
"t3": 0
}
]
}],
"count":1
}



first you need to get the array length / depth of array objects
then you need to iterated it over the array
in my case order.object is pointer to object array.

if Json.has(order.object, "downTime") then
downtime.array = Json.get(order.object,"downTime")
if Json.type(Json.get(order.object,"downTime")) = JSON_TYPE_ARRAY then
downtime.count = Json.count(Json.get(order.object,"downTime"))
endif
for j = 1 to downtime.count
downtime.object = Json.at(downtime.array,j)
if Json.type(downtime.object) = JSON_TYPE_OBJECT then
read.prod.order.downtime.from.json()

endif
endfor
endif

Then get the values for each element of the array.

function void read.prod.order.downtime.from.json()
{

init.prod.order.downtime.fields()

if Json.has(downtime.object, "time") then

if Json.type(Json.get(downtime.object,"time")) = JSON_TYPE_NUMBER then
bl.minutes.down = Json.getnumber(downtime.object, "time")
endif
if Json.type(Json.get(downtime.object,"time")) = JSON_TYPE_STRING then
bl.minutes.down = lval(Json.getString(downtime.object, "time"))
endif
endif
if Json.has(downtime.object, "t1") then
if Json.type(Json.get(downtime.object,"t1")) = JSON_TYPE_NUMBER then
bl.t1 = str$(Json.getnumber(downtime.object, "t1"))
endif
if Json.type(Json.get(downtime.object,"t1")) = JSON_TYPE_STRING then
bl.t1 = Json.getString(downtime.object, "t1")
endif
endif

}

jerrygjj
10th August 2022, 04:01
Thank you for your help. I will test it and feedback to you late. Thank you so much.