You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I've been working with this JSON parser and have found it to be impressively fast. However, I have encountered a challenge for which I am seeking a solution.
When I retrieve an existing element, such as: testSTR := json.Element('integer1').AsString();
this works perfectly. However, if I attempt to retrieve an element that does not exist: testSTR := json.Element('integer123').AsString();
the PLC locks down and throws an exception.
Is there a method to check for the presence of an element before attempting to retrieve it, or alternatively, return an empty string if the element is not found? This functionality is crucial as the data from HTTP requests may vary in structure.
The text was updated successfully, but these errors were encountered:
METHOD Parse : ReplyITF
VAR_INPUT
pMsg:POINTER TO STRING;
END_VAR
VAR
decoder:JsonDecoder;
element: IJSONElement;
val:STRING;
encoder:JsonDecoder;
END_VAR
decoder.Decode(pMsg^);
element:=decoder.Element('cid');
IF element = 0 THEN
// ELEMENT NOT FOUND!!!!!!!
END_IF
I've been working with this JSON parser and have found it to be impressively fast. However, I have encountered a challenge for which I am seeking a solution.
Consider the following example:
json.Decode('{ "integer1": 5, "string1": "la", "null1": null, "mixedNestedArray": [{"name": "Nested object"}, 4, true, [null, null, 5] ], "object1" : { "subint1":5, "substring1":"lala", "subfloat1":5.44 }, "string2": "asdf", "array2" : [5,4] }');
When I retrieve an existing element, such as:
testSTR := json.Element('integer1').AsString();
this works perfectly. However, if I attempt to retrieve an element that does not exist:
testSTR := json.Element('integer123').AsString();
the PLC locks down and throws an exception.
Is there a method to check for the presence of an element before attempting to retrieve it, or alternatively, return an empty string if the element is not found? This functionality is crucial as the data from HTTP requests may vary in structure.
The text was updated successfully, but these errors were encountered: