Welcome to our new forum
All users of the legacy CODESYS Forums, please create a new account at account.codesys.com. But make sure to use the same E-Mail address as in the old Forum. Then your posts will be matched.
Close
Hi, I'm trying to get this to work, I need to parse a json string returned by a REST API, but when I call ParseJson my structures never seem to get populated?
Yes, if you're using STRUCT_TO_JSON within a function block, you'll have to adjust the MaxLevel input to suit your application. There's a long comment in the function block that explains how to use it.
For JSON_TO_STRUCT, can you post an example or something? Are you certain that there is data in your JSON string before Execute is called? It will only run once on the string when it sees the rising edge of Execute.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
It works fine with my real world API strings just not the example thats posted - I think because it has the name of the object at the beginning of the string?
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Probably. When I developed this library, that was probably the biggest recurring issue--trying to consistently parse or compose with such a wide variety of possible strings and variable structures, arrays, named objects vs, unnamed, etc. The MaxLevel input was sort of a compromise--it works but I've never really liked it.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hi, I'm trying to get this to work, I need to parse a json string returned by a REST API, but when I call ParseJson my structures never seem to get populated?
Talk Topic about project #pro-json
I copied the posted example and ComposeJSON never populates JSONString? I am using Codesys 3.5 SP 19
It seems like the issue relates to using within a function rather than prg block
This has fixed ComposeJson, however using the example is still not working with ParseJSON
Yes, if you're using STRUCT_TO_JSON within a function block, you'll have to adjust the MaxLevel input to suit your application. There's a long comment in the function block that explains how to use it.
For JSON_TO_STRUCT, can you post an example or something? Are you certain that there is data in your JSON string before Execute is called? It will only run once on the string when it sees the rising edge of Execute.
It works fine with my real world API strings just not the example thats posted - I think because it has the name of the object at the beginning of the string?
Which example program? There were a few different ones.
The one here: https://forge.codesys.com/lib/pro-json/home/Home/ but seems like it will be MaxLevel setting again
Probably. When I developed this library, that was probably the biggest recurring issue--trying to consistently parse or compose with such a wide variety of possible strings and variable structures, arrays, named objects vs, unnamed, etc. The MaxLevel input was sort of a compromise--it works but I've never really liked it.