News:

  • May 14, 2026, 01:34:31 PM

Login with username, password and session length

Author Topic: String Parsing Issue  (Read 6597 times)

PLCwannabe

  • Hero Member
  • *****
  • Posts: 208
String Parsing Issue
« on: December 08, 2025, 11:00:36 AM »
See attached. I'm trying to retrieve "currentValue" from string SL0.  The instruction completes every time, but always returns value 3.0, rather than the expected value 7.0  . What could be the problem here? All the registers are only being used in that rung, I've tried using different registers, still getting the same results. If I use a string as the result, everything works correctly.

franji1

  • Bit Weenie
  • Host Moderator
  • Hero Member
  • *****
  • Posts: 3814
    • Host Engineering
Re: String Parsing Issue
« Reply #1 on: December 08, 2025, 11:24:49 AM »
You don't utilize the Return Result of your JSONPARSE.  It is probably failing because the value is NOT numeric, but is a STRING containing the text of a numeric value (that string could be "ABC", not "123").

The difference is the key/value pair of
"currentValue":"7.0"
"currentValue":7.0
(notice the difference?)

You will need to put the value of JSONPARSE key into another STRING element (e.g. SS0), then use a STR2REAL instruction to convert SS0 to KETherm25.


BobO

  • Host Moderator
  • Hero Member
  • *****
  • Posts: 6156
  • Yes Pinky, Do-more will control the world!
Re: String Parsing Issue
« Reply #2 on: December 08, 2025, 11:31:47 AM »
See attached. I'm trying to retrieve "currentValue" from string SL0.  The instruction completes every time, but always returns value 3.0, rather than the expected value 7.0  . What could be the problem here? All the registers are only being used in that rung, I've tried using different registers, still getting the same results. If I use a string as the result, everything works correctly.

The value type is a string. When you assign a string to numeric, it just stuffs the length rather than attempting any form of conversion. I probably wouldn't have returned a float value as a string, particularly since they already had a string description, but that's what they've done.
"It has recently come to our attention that users spend 95% of their time using 5% of the available features. That might be relevant." -BobO

PLCwannabe

  • Hero Member
  • *****
  • Posts: 208
Re: String Parsing Issue
« Reply #3 on: December 08, 2025, 11:41:10 AM »
Right on. Thanks guys.