- You are here:
- Home
- CodeXchange
- All
- PowerBuilder
- WebAPI JSON to DataWindow
WebAPI JSON to DataWindow
- * Appeon *
- Code Author
- Offline
Less
More
- Posts: 159
5 years 11 months ago - 3 years 10 months ago #82
by * Appeon *
This message has an attachment file.
* Appeon * created the code: WebAPI JSON to DataWindow
This sample shows how you can interacts with WebAPI addresses by calling the HttpClient and JsonParser objects.
Development Requirements:
IDE: PowerBuiler 2017 R2 or above
Development Requirements:
IDE: PowerBuiler 2017 R2 or above
This message has an attachment file.
Please log in or register to see it.
Last Edit: 3 years 10 months ago by * Appeon *. Reason: Update Demo
Please Log in or Create an account to join the conversation.
- Systeembeheer SFR
- Offline
Less
More
- Posts: 8
3 years 9 months ago #337
by Systeembeheer SFR
Systeembeheer SFR replied the code: WebAPI JSON to DataWindow
hi
Just to update: it's working now
After installing Appeon Workspace build 2670 it worked. Still have to install R3 PB but now I va got a working scipt, even reading the scale over the WiFi.
Thanks for the help
Just to update: it's working now
After installing Appeon Workspace build 2670 it worked. Still have to install R3 PB but now I va got a working scipt, even reading the scale over the WiFi.
Thanks for the help
Please Log in or Create an account to join the conversation.
- Systeembeheer SFR
- Offline
Less
More
- Posts: 8
3 years 9 months ago #336
by Systeembeheer SFR
Systeembeheer SFR replied the code: WebAPI JSON to DataWindow
hi
Just to update: it's working now
After installing Appeon Workspace build 2670 it worked. Still have to install R3 PB but now I va got a working scipt, even reading the scale over the WiFi.
Thanks for the help
Just to update: it's working now
After installing Appeon Workspace build 2670 it worked. Still have to install R3 PB but now I va got a working scipt, even reading the scale over the WiFi.
Thanks for the help
Please Log in or Create an account to join the conversation.
- Govinda Lopez @Appeon
- Offline
Less
More
- Posts: 7
3 years 10 months ago - 3 years 10 months ago #335
by Govinda Lopez @Appeon
Govinda Lopez @Appeon replied the code: WebAPI JSON to DataWindow
Hi Systeembeheer SFR,
It might seem that your URL contains a private IP. If that is the case you might want to double check that your mobile device is in the same network and can access that URL. If this is the case, then you might want to try using the HTTPClient and/or open a support ticket instead.
You can also take this question to the community's Q&A section too. That way you can also get more suggestions too.
The Inet object and its GetUrl() function are both supported in the latest version of PowerServer Mobile. ( docs.appeon.com/ps2020/features_help_for...le.html#Objects_Inet )
Regards,
It might seem that your URL contains a private IP. If that is the case you might want to double check that your mobile device is in the same network and can access that URL. If this is the case, then you might want to try using the HTTPClient and/or open a support ticket instead.
You can also take this question to the community's Q&A section too. That way you can also get more suggestions too.
The Inet object and its GetUrl() function are both supported in the latest version of PowerServer Mobile. ( docs.appeon.com/ps2020/features_help_for...le.html#Objects_Inet )
Regards,
Last Edit: 3 years 10 months ago by Govinda Lopez @Appeon. Reason: Added more content
Please Log in or Create an account to join the conversation.
- Systeembeheer SFR
- Offline
Less
More
- Posts: 8
3 years 10 months ago #334
by Systeembeheer SFR
Systeembeheer SFR replied the code: WebAPI JSON to DataWindow
Dear Govinda,
Thanks for your help. It's a struggle. Your script seems to work perfectly...on my desktop and is reading the kg out of the scale
Great
But when applying this to the app in de appeon app on my tablet it's not working.
It took me a while and a lot of tests to see why.
Apparently the app does nog like the orange line. Running this URL in google, i get a good response. But doing the some within the app and this code the scale response with: INDEX UNKNOW
Do you know it powerserver app can understand the geturl function (i look it up and it should). I also tried all ways with or without http:// etc. I am running out of options, but i am sure i am really close
I really appreciated all your work so far. Thanks in advance
/////code//////
inet linet_main
n_cst_internet luo_data // as defined above
linet_main = CREATE inet
luo_data = CREATE n_cst_internet
li_rc = &
linet_main.GetURL("http://172.16.12.50:9094/?index=1", luo_data)
SetPointer(Arrow!)
IF li_rc = 1 THEN
///here goes your code
Thanks for your help. It's a struggle. Your script seems to work perfectly...on my desktop and is reading the kg out of the scale
Great
But when applying this to the app in de appeon app on my tablet it's not working.
It took me a while and a lot of tests to see why.
Apparently the app does nog like the orange line. Running this URL in google, i get a good response. But doing the some within the app and this code the scale response with: INDEX UNKNOW
Do you know it powerserver app can understand the geturl function (i look it up and it should). I also tried all ways with or without http:// etc. I am running out of options, but i am sure i am really close
I really appreciated all your work so far. Thanks in advance
/////code//////
inet linet_main
n_cst_internet luo_data // as defined above
linet_main = CREATE inet
luo_data = CREATE n_cst_internet
li_rc = &
linet_main.GetURL("http://172.16.12.50:9094/?index=1", luo_data)
SetPointer(Arrow!)
IF li_rc = 1 THEN
///here goes your code
Please Log in or Create an account to join the conversation.
- Govinda Lopez @Appeon
- Offline
Less
More
- Posts: 7
3 years 10 months ago #333
by Govinda Lopez @Appeon
Govinda Lopez @Appeon replied the code: WebAPI JSON to DataWindow
Hi Systeembeheer SFR,
Using POS to obtain the value is a good approach you can use for PowerServer Mobile. You could do something like this:
You can reduce the amount of lines of code, of course, but I just placed them like so as an example. You can also test this code and make changes as necessary.
I hope this helps.
Regards,
Using POS to obtain the value is a good approach you can use for PowerServer Mobile. You could do something like this:
// Get the position of the "net" string
li_positie = POS(ls_stringtotaal, '"net":')
// Strip out the first part of the string for ease of use
ls_temp = MID(ls_stringtotaal, li_positie + 6)
// You can use either of these lines depending on the composition of your JSON string
//li_positie = POS(ls_temp, 'consecNumber') - 2
li_positie = POS(ls_temp, ',"')
// Get the value of the kg as needed
ls_kg = MID(ls_temp, 1, li_positie - 1) + " kg"
You can reduce the amount of lines of code, of course, but I just placed them like so as an example. You can also test this code and make changes as necessary.
I hope this helps.
Regards,
Please Log in or Create an account to join the conversation.
- Systeembeheer SFR
- Offline
Less
More
- Posts: 8
3 years 10 months ago #332
by Systeembeheer SFR
Systeembeheer SFR replied the code: WebAPI JSON to DataWindow
Ho Govinda Lopez
Thanks for your quick reply. To bat it's nog supported yet.
This leaves me with a small problem, maybe you can help me one more time.
I got this string out of our scale:
{"grossavg":0,"freefall1":0,"futurenet2":2.3,"tare":0,"target":0,"freefall2":0,"curDigitsTotal":5,"inGrossBand":false,"max":28923.3,"count":5,"pcwt":0.45359237,"futurenet1":2.3,"lastsample":1,"curCapacity":500,"adc":84489,"netmin":-1.9,"ntot":0,"roc":0,"units":2,"min":-1.9,"ctot":0,"hiresnet":2.317815209042,"gtot":0,"referenceWeight":0,"curDigitsRight":1,"resultdescr":"LIVE SUCCESS","curDivision":0.1,"ntotcal":0,"inmotion":0,"hiresgross":2.317815209042,"unitsStr":"kg","holdCounts":0,"gtotcal":0,"netavg":0,"net":2.3,"consecNumber":0,"gross":2.3,"netmax":28923.3,"futuregross1":2.3,"inmohiresnet":0,"percent":0,"underRange":false,"countavg":0,"futuregross2":2.3,"overRange":false,"resultnr":0,"holdEnabled":false,"inmohiresgross":0,"ntotpluscur":2.3,"ntotminuscur":-2.3,"gtotpluscur":2.3,"ctotminuscur":-5,"pcwtx1k":453.59237,"ctotpluscur":5,"gtotminuscur":-2.3,"curUnitsFactor":0.45359237,"motion":false,"datetimestamp":"04/01/2021 17:31:18","scaleId":1,"serialnumber":"191650375","tran":0,"centerZero":false,"adcTimeUSec":274630,"curDigitsLeft":3,"timeStamp":1609781478}
I am after the kg of the scale, they can be found after "net"
I am using the function POS now: li_positie=Pos(ls_stringtotaal, "net")
For some reason it's reconising the same as Json that this is position 36. That is correct
I just don't know how to get the kg out of this. So in this case 2,3 kg.
Is there an other function to desilate the value out of this position?
Hope to here from you
Thanks for your quick reply. To bat it's nog supported yet.
This leaves me with a small problem, maybe you can help me one more time.
I got this string out of our scale:
{"grossavg":0,"freefall1":0,"futurenet2":2.3,"tare":0,"target":0,"freefall2":0,"curDigitsTotal":5,"inGrossBand":false,"max":28923.3,"count":5,"pcwt":0.45359237,"futurenet1":2.3,"lastsample":1,"curCapacity":500,"adc":84489,"netmin":-1.9,"ntot":0,"roc":0,"units":2,"min":-1.9,"ctot":0,"hiresnet":2.317815209042,"gtot":0,"referenceWeight":0,"curDigitsRight":1,"resultdescr":"LIVE SUCCESS","curDivision":0.1,"ntotcal":0,"inmotion":0,"hiresgross":2.317815209042,"unitsStr":"kg","holdCounts":0,"gtotcal":0,"netavg":0,"net":2.3,"consecNumber":0,"gross":2.3,"netmax":28923.3,"futuregross1":2.3,"inmohiresnet":0,"percent":0,"underRange":false,"countavg":0,"futuregross2":2.3,"overRange":false,"resultnr":0,"holdEnabled":false,"inmohiresgross":0,"ntotpluscur":2.3,"ntotminuscur":-2.3,"gtotpluscur":2.3,"ctotminuscur":-5,"pcwtx1k":453.59237,"ctotpluscur":5,"gtotminuscur":-2.3,"curUnitsFactor":0.45359237,"motion":false,"datetimestamp":"04/01/2021 17:31:18","scaleId":1,"serialnumber":"191650375","tran":0,"centerZero":false,"adcTimeUSec":274630,"curDigitsLeft":3,"timeStamp":1609781478}
I am after the kg of the scale, they can be found after "net"
I am using the function POS now: li_positie=Pos(ls_stringtotaal, "net")
For some reason it's reconising the same as Json that this is position 36. That is correct
I just don't know how to get the kg out of this. So in this case 2,3 kg.
Is there an other function to desilate the value out of this position?
Hope to here from you
Please Log in or Create an account to join the conversation.
- Govinda Lopez @Appeon
- Offline
Less
More
- Posts: 7
3 years 10 months ago #330
by Govinda Lopez @Appeon
Govinda Lopez @Appeon replied the code: WebAPI JSON to DataWindow
Hi Systeembeheer SFR,
Currently the JSONGenerator, JSONParser and JSONPackage objects are not supported in PowerServer Mobile ( docs.appeon.com/ps2020/features_help_for...pported_objects.html ).
Regards,
Currently the JSONGenerator, JSONParser and JSONPackage objects are not supported in PowerServer Mobile ( docs.appeon.com/ps2020/features_help_for...pported_objects.html ).
Regards,
Please Log in or Create an account to join the conversation.
- Systeembeheer SFR
- Offline
Less
More
- Posts: 8
3 years 10 months ago #329
by Systeembeheer SFR
Systeembeheer SFR replied the code: WebAPI JSON to DataWindow
Hi Govinda Lopes,
Thanks for your help so far. It works great.
Only thing that's not working it to get it working on the appeaon mobile workspace
The tablet can read the scale trough google browser
The server with powerserver kan read the scale trough google browser. (the scale is in our netwerk)
But within the appeon mobile workspace it will not read the scale. IS json code working on the appeon mobile workspace. (same code starting from powerbuilder on a desktop in the same network works fine)
Thanks for your help so far. It works great.
Only thing that's not working it to get it working on the appeaon mobile workspace
The tablet can read the scale trough google browser
The server with powerserver kan read the scale trough google browser. (the scale is in our netwerk)
But within the appeon mobile workspace it will not read the scale. IS json code working on the appeon mobile workspace. (same code starting from powerbuilder on a desktop in the same network works fine)
Attachments:
Please Log in or Create an account to join the conversation.
- Govinda Lopez @Appeon
- Offline
Less
More
- Posts: 7
3 years 10 months ago #318
by Govinda Lopez @Appeon
Govinda Lopez @Appeon replied the code: WebAPI JSON to DataWindow
Hi Systeembeheer SFR,
The JsonItemType enumerated values are:
JsonStringItem! -- Type of the JSON node whose key value pair is a string, such as "name":"evan".
JsonNumberItem! -- Type of the JSON node whose key value pair is a number, such as "id":1001.
JsonBooleanItem! -- Type of the JSON node whose key value pair is a boolean, such as "active":true.
JsonNullItem! -- Type of the JSON node whose key value pair is null, such as "remark": null.
JsonObjectItem! -- Type of the JSON node whose key value pair is an object, such as "date_object":{"datetime":7234930293, "date": "2017-09-21", "time": "12:00:00"}.
JsonArrayItem! -- Type of the JSON node whose key value pair is an array, such as "department_array":[999999, {"name":"Website"}, {"name":"PowerBuilder"}, {"name":"IT"}].
You may find more info about it here: docs.appeon.com/pb2019r2/powerscript_reference/ch10s278.html
So you might want to cycle through the JSON looking for your key:value pair "net":500.9 in your example.
I hope this helps.
Regards,
The JsonItemType enumerated values are:
JsonStringItem! -- Type of the JSON node whose key value pair is a string, such as "name":"evan".
JsonNumberItem! -- Type of the JSON node whose key value pair is a number, such as "id":1001.
JsonBooleanItem! -- Type of the JSON node whose key value pair is a boolean, such as "active":true.
JsonNullItem! -- Type of the JSON node whose key value pair is null, such as "remark": null.
JsonObjectItem! -- Type of the JSON node whose key value pair is an object, such as "date_object":{"datetime":7234930293, "date": "2017-09-21", "time": "12:00:00"}.
JsonArrayItem! -- Type of the JSON node whose key value pair is an array, such as "department_array":[999999, {"name":"Website"}, {"name":"PowerBuilder"}, {"name":"IT"}].
You may find more info about it here: docs.appeon.com/pb2019r2/powerscript_reference/ch10s278.html
So you might want to cycle through the JSON looking for your key:value pair "net":500.9 in your example.
I hope this helps.
Regards,
Please Log in or Create an account to join the conversation.
- Systeembeheer SFR
- Offline
Less
More
- Posts: 8
3 years 10 months ago #317
by Systeembeheer SFR
Systeembeheer SFR replied the code: WebAPI JSON to DataWindow
hi,
i am struggeling with this code. In the demo it works fine.
If i try my own wepapi call, the data is shown in the responce / json TAB precily and the same if I look trought a browser. So far so good.
I made a new datawindow with a kolom NET
in the of_importdata line 104 there is an if functie, and there it stops. It will not put the data in the datawindow
See attachment yellow line.
is says here :
// Array item is JsonObjectItem!
if inv_jsonParser.GetItemType(ll_ObjectItem) = JsonObjectItem! then
ll_objectitem = 2
I can;t find why inv_jsonParser.GetItemType(ll_ObjectItem) = JsonObjectItem! What is the code cheking here, and what is the JsonObjectItem!
I only want the NET out of the follwoing json code:
{"grossavg":0,"freefall1":0,"futurenet2":500.9,"tare":0,"target":0,"freefall2":0,"curDigitsTotal":5,"inGrossBand":false,"max":500.9,"count":0,"pcwt":0.45359237,"futurenet1":500.9,"lastsample":1,"curCapacity":500,"adc":8520167,"netmin":500.9,"ntot":0,"roc":0,"units":2,"min":500.9,"ctot":0,"hiresnet":0,"gtot":0,"referenceWeight":0,"curDigitsRight":1,"resultdescr":"LIVE SUCCESS","curDivision":0.1,"ntotcal":0,"inmotion":0,"hiresgross":500.9,"unitsStr":"kg","holdCounts":0,"gtotcal":0,"netavg":0,"net":500.9,"consecNumber":0,"gross":500.9,"netmax":500.9,"futuregross1":500.9,"inmohiresnet":0,"percent":0,"underRange":false,"countavg":0,"futuregross2":500.9,"overRange":true,"resultnr":0,"holdEnabled":false,"inmohiresgross":0,"ntotpluscur":500.9,"ntotminuscur":-500.9,"gtotpluscur":500.9,"ctotminuscur":0,"pcwtx1k":453.59237,"ctotpluscur":0,"gtotminuscur":-500.9,"curUnitsFactor":0.45359237,"motion":false,"datetimestamp":"18/12/2020 15:41:06","scaleId":1,"serialnumber":"191650375","tran":0,"centerZero":false,"adcTimeUSec":2648610,"curDigitsLeft":3,"timeStamp":1608306066}
SOmeone any ideaa how to fix this
Thanks in advanged
i am struggeling with this code. In the demo it works fine.
If i try my own wepapi call, the data is shown in the responce / json TAB precily and the same if I look trought a browser. So far so good.
I made a new datawindow with a kolom NET
in the of_importdata line 104 there is an if functie, and there it stops. It will not put the data in the datawindow
See attachment yellow line.
is says here :
// Array item is JsonObjectItem!
if inv_jsonParser.GetItemType(ll_ObjectItem) = JsonObjectItem! then
ll_objectitem = 2
I can;t find why inv_jsonParser.GetItemType(ll_ObjectItem) = JsonObjectItem! What is the code cheking here, and what is the JsonObjectItem!
I only want the NET out of the follwoing json code:
{"grossavg":0,"freefall1":0,"futurenet2":500.9,"tare":0,"target":0,"freefall2":0,"curDigitsTotal":5,"inGrossBand":false,"max":500.9,"count":0,"pcwt":0.45359237,"futurenet1":500.9,"lastsample":1,"curCapacity":500,"adc":8520167,"netmin":500.9,"ntot":0,"roc":0,"units":2,"min":500.9,"ctot":0,"hiresnet":0,"gtot":0,"referenceWeight":0,"curDigitsRight":1,"resultdescr":"LIVE SUCCESS","curDivision":0.1,"ntotcal":0,"inmotion":0,"hiresgross":500.9,"unitsStr":"kg","holdCounts":0,"gtotcal":0,"netavg":0,"net":500.9,"consecNumber":0,"gross":500.9,"netmax":500.9,"futuregross1":500.9,"inmohiresnet":0,"percent":0,"underRange":false,"countavg":0,"futuregross2":500.9,"overRange":true,"resultnr":0,"holdEnabled":false,"inmohiresgross":0,"ntotpluscur":500.9,"ntotminuscur":-500.9,"gtotpluscur":500.9,"ctotminuscur":0,"pcwtx1k":453.59237,"ctotpluscur":0,"gtotminuscur":-500.9,"curUnitsFactor":0.45359237,"motion":false,"datetimestamp":"18/12/2020 15:41:06","scaleId":1,"serialnumber":"191650375","tran":0,"centerZero":false,"adcTimeUSec":2648610,"curDigitsLeft":3,"timeStamp":1608306066}
SOmeone any ideaa how to fix this
Thanks in advanged
Attachments:
Please Log in or Create an account to join the conversation.
Moderators: Appeon Administrator