Hi I-zy
There is currently no way you can do this without writing at least a little script. Here is an example panel that pulls the "name" field out of a JSON response. If the field in the example, If I wanted to get to a specific "topping", the var field = jsonObject["name"]; would change to something like: var field = jsonObject["topping"][2]["type"]; and then your parameter would show "Sugar".
<abs contexttype="opengear" keepalive="true" style="bg#dark;">
<meta>
<params>
<param access="1" maxlength="0" name="Value I Want" oid="Value_I_Want" type="STRING" value="" widget="text"/>
</params>
</meta>
<param expand="true" height="43" left="144" oid="Value_I_Want" top="59" width="273"/>
<label height="51" left="30" name="Value I Want: " style="txt-align:east" top="56" width="110"/>
<button buttontype="push" height="49" left="426" name="Parse JSON" top="58" width="107">
<task tasktype="ogscript">var jsonString = '{\
"id": "0001", \
"type": "donut", \
"name": "Cake", \
"ppu": 0.55, \
"batters": \
{ \
"batter": \
[ \
{ "id": "1001", "type": "Regular" }, \
{ "id": "1002", "type": "Chocolate" }, \
{ "id": "1003", "type": "Blueberry" }, \
{ "id": "1004", "type": "Devil\'s Food" } \
] \
}, \
"topping": \
[ \
{ "id": "5001", "type": "None" }, \
{ "id": "5002", "type": "Glazed" }, \
{ "id": "5005", "type": "Sugar" }, \
{ "id": "5007", "type": "Powdered Sugar" }, \
{ "id": "5006", "type": "Chocolate with Sprinkles" }, \
{ "id": "5003", "type": "Chocolate" }, \
{ "id": "5004", "type": "Maple" } \
] \
} ';
function callback(resultStr)
{
if (resultStr == null) // THIS CODE RUNS IF NOTHING WAS FETCHED FROM THE WEB SERVER
{
return;
}
var jsonObject = JSON.parse(resultStr); // TRANSFORM THE RAW TEXT DATA INTO A JSON OBJECT
var field = jsonObject["name"]; // THIS IS HOW I ACCESS THE "NAME" FIELD IN THE OBJECT
params.setValue('Value_I_Want', 0, field); // THIS IS HOW I AM SETTING THE PARAMETER I WILL SEE ON SCREEN
}
//ogscript.asyncPost('http://this-is-where-my-json-is', null, callback); //USE THIS LINE TO GET YOUR REAL JSON FILE
callback(jsonString); //COMMENT THIS OUT TO STOP USING MY EXAMPLE JSON
</task>
</button>
</abs>
------------------------------
James Peltzer
Ross Video
------------------------------
Original Message:
Sent: 02-12-2023 18:34
From: I-zy
Subject: Read online Json and display specific Keys from it on the dashboard
I want to read an online Json and load a specific Key from it and display it on the dashboard.
Like Datalinq, values<2>array<3>.
After reading this post, I was able to view the contents of the Json, but I can't specify a specific Key.
https://livinglive.community/communities/community-home/digestviewer/viewthread?GroupId=205&MessageKey=17930b1e-af9b-4760-ad3a-007daeb3e9c8&CommunityKey=94781415-eb0f-4f9a-b891-c44d41d870c8&tab=digestviewer
- When Json is updated, the values are also automatically updated.
- I am unable to script. Can this be done in visual Logic?
- I'm not very good at English, so sorry if it's hard to read.
------------------------------
I-zy I-zy
Xpressioner
monoly
Japan
------------------------------