ParseJSON failed with Version 1.0.0.13/14 & codesys v3.5 sp17/sp18, the NewJSONObj get no value.
Talk Topic about project #pro-json
If you post an example of the JSON string I can take a look at it.
I use the ExampleJSON_PRG.
ok yeah, that's not actually a great example. I'll make some better ones.
The resulting JSON string from ComposeJSON looks like this:
{"LocalJSONObj":{"var1":true,"var2":34.8756,"var3":"teststring","obj":{"var4":22,"var5":false,"var6":"qwer","var7":[123.234,55.46001,985]},"arrayobj":[1,2,3]}}
It's created an object starting at the first level "LocalJSONObj" variable. Therefore, it doesn't match the "NewJSONObj" variable in the parse
There's two ways to fix this: 1.Use a different string on the parse
NewJSONStr: STRING(1000):= '{"NewJSONObj":{"var1":true,"var2":34.8756,"var3":"teststring","obj":{"var4":22,"var5":false,"var6":"qwer","var7":[123.234,55.46001,985]},"arrayobj":[1,2,3]}}'; ParseJSON( JSONString:= ADR(NewJSONStr), JSONStringSize:= SIZEOF(NewJSONStr), JSONVars:= ADR(NewJSONObj), NumberOfVars:= SIZEOF(NewJSONObj) / SIZEOF(JSONVAR) );
OR
2.Set the "MaxLevels" input on the compose to 1. Then you can parse it into any variable that has the same structure.
ComposeJSON( JSONString:= ADR(JSONString), JSONStringSize:= SIZEOF(JSONString), MaxLevel:= 1, JSONVars:= ADR(LocalJSONObj), NumberOfVars:= SIZEOF(LocalJSONObj) / SIZEOF(JSONVAR) );
This will prevent creating an object for the "LocalJSONObj" variable, so your resulting string will look like this:
{"var1":true,"var2":34.8756,"var3":"teststring","obj":{"var4":22,"var5":false,"var6":"qwer","var7":[123.234,55.46001,985]},"arrayobj":[1,2,3]}
Got it. Thank you tvm.
Log in to post a comment.
ParseJSON failed with Version 1.0.0.13/14 & codesys v3.5 sp17/sp18, the NewJSONObj get no value.
Talk Topic about project #pro-json
more posts ...
If you post an example of the JSON string I can take a look at it.
I use the ExampleJSON_PRG.
ok yeah, that's not actually a great example. I'll make some better ones.
The resulting JSON string from ComposeJSON looks like this:
{"LocalJSONObj":{"var1":true,"var2":34.8756,"var3":"teststring","obj":{"var4":22,"var5":false,"var6":"qwer","var7":[123.234,55.46001,985]},"arrayobj":[1,2,3]}}
It's created an object starting at the first level "LocalJSONObj" variable. Therefore, it doesn't match the "NewJSONObj" variable in the parse
There's two ways to fix this:
1.Use a different string on the parse
OR
2.Set the "MaxLevels" input on the compose to 1. Then you can parse it into any variable that has the same structure.
This will prevent creating an object for the "LocalJSONObj" variable, so your resulting string will look like this:
{"var1":true,"var2":34.8756,"var3":"teststring","obj":{"var4":22,"var5":false,"var6":"qwer","var7":[123.234,55.46001,985]},"arrayobj":[1,2,3]}
Last edit: tvm 2022-12-03
Got it. Thank you tvm.