ā02-24-2020 08:33 AM
Hello,
I have a JSON reply from a device and need to decode a number of values from it that correspond to 4 values from 6 analog channels. I have looked and tried to work with the examples but needed a little bit more help if anyone can.
Thank you in advance
Lee
Solved! Go to Solution.
ā02-24-2020 09:04 AM
Hi Lee,
which kind of problems do you got?
The straight forward way is to use MatchPattern/ScanFromString several times on your JSON text. (Search for "channelData", then search for "id", then scan for needed valuesā¦)
Other options include using one of the available JSON toolkits to parse the objectā¦
ā02-24-2020 09:32 AM
Hello,
Thank you - I understand both of your approaches. I dont have a toolkit and the first approach seems the wrong approach and messy to me, am i not able to make use of the unflatten from JSON function? or would that not be enough?
ā02-24-2020 09:58 AM
ā02-24-2020 10:41 AM
Hello
I can see where you are going with this, thank you.
My problem is working out how to construct the cluster as i am not sure what are names or values or what type of data is coming. If that makes sense
Lee
ā02-24-2020 11:42 AM
Hello,
OK so that is great i can see how to decode the output now - fantastic, thank you.
I have a similar issue now going the other way - sending a JSON command
This is the data I have on it, i wondered if you can help with this also?
{"jsonrpc":"2.0", "id":0, "method":"setAlarms",
"params":{
"alarms":[
{āchannelā:0,ālevelHighā:300},
{āchannelā:1,ālevelHighā:300},
...
]
}
}
Response when ok:
{"jsonrpc":2.0,"id":0,"result":null}
ā02-25-2020 04:25 AM
Not sure if\how the null can be done. But you can always use a string constant "{"jsonrpc":2.0,"id":0,"result":null}" as it's a static reply.
ā02-25-2020 07:37 AM
Fantastic thank you, I can structure the message now to send to the device.
One final last 'thing' is that the levelHigh number needs to be floating point but after I go through the json function it displays 22 but i need it to show 22.0 (i have changed the levelHigh number format but it doesnt go through)/
ā02-25-2020 07:52 AM
There's no control over that with the build-in LV JSON tools. And it shouldn't matter. "22" is still "22.0" when you read it as a double. I'm not sure if other tools allow specifying this.
The only way you can force the 22.0 in the string, is to make a reg.ex. to replace that. But AFAIC, you shouldn't need to.
The reg.ex. won't be trivial...
ā02-25-2020 07:59 AM
Yea, the device manufacturer are telling me it has to be floating point. If i manually manipulate the resulting string from the function the device responds correctly.
Not sure where to go from here now