JSON parsing and composing library:

mikek10
2023-06-12
2024-07-12
  • mikek10 - 2023-06-12

    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

     
  • mikek10 - 2023-06-12

    I copied the posted example and ComposeJSON never populates JSONString? I am using Codesys 3.5 SP 19

     
  • mikek10 - 2023-06-12

    It seems like the issue relates to using within a function rather than prg block

     
    • mikek10 - 2023-06-12

      This has fixed ComposeJson, however using the example is still not working with ParseJSON

       
  • tvm - 2023-06-12

    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.

     
  • mikek10 - 2023-06-12

    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?

     
  • tvm - 2023-06-12

    Which example program? There were a few different ones.

     
  • tvm - 2023-06-12

    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.

     

Log in to post a comment.