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

How to sort JSON object in codesys

garrian
2024-05-04
2024-05-08
  • garrian - 2024-05-04

    Hi there,

    I'm testing out MQTT from my Wago PLC using JSON object. I have managed to publish this {"Temperature":15.6,"Setpoint":38.0} to my broker. Now I', trying to subscribe to the same message. The result is this:
    '{"Temperature":15.6,"Setpoint":38.0}95}ê$10šå$04$Nå$08²Ÿå$0B` á$08@šå'

    First, why do I see 95}ê$10šå$04$Nå$08²Ÿå$0B` á$08@šå' at the end of the message?

    Second, how Can i sort out this data to use it in my program? I followed a youtube tutorial which gave me the attached result, which works. But I need some other smart way of doing this when the object gets even more data in it.

    Any help is very appreciated :)

     
  • yannickasselin - 2024-05-08

    Just adding:
    sSubscriberdata := '';
    Right before your memcopy should fix the extra characters. It is because your are copying 36 characters into a string which can contain more than 36 characters and there is garbage left in the extra characters.

    Regarding the parsing of json, I usually build a structure that mirrors the json data and use the available methods in the IIoT library to parse the data and fill the structure.

     

    Last edit: yannickasselin 2024-05-08

Log in to post a comment.