JSON parsing

Avatar
  • updated

I created a TcpServer with a JSON parser:

Image 4625

I added a string parser with a token :

Image 4627


I use Postman and send :

{"TestData":{"Data1":"1"}}


ComfortClick receives data:

POST / HTTP/1.1

Content-Type: text/plain

User-Agent: PostmanRuntime/7.32.3

Accept: */*

Postman-Token: e79d7b2e-8a0a-4ef6-bd47-8d5cc7e8c6f3

Host: 192.168.1.7:16900

Accept-Encoding: gzip, deflate, br

Connection: keep-alive

Content-Length: 26


{"TestData":{"Data1":"1"}}


But the parser throws an error:

Devices : 15.08.2023 14:54:09 : Error : Devices\Test\String : Error parsing received data. Unexpected character encountered while parsing value: P. Path , line 0, position 0. w Newtonsoft.Json.JsonTextReader.ParseValue()

w Newtonsoft.Json.Linq.JObject.Load(JsonReader reader, JsonLoadSettings settings)

w Newtonsoft.Json.Linq.JObject.Parse(String json, JsonLoadSettings settings)

w ComfortClick.Tasks.Common.ReceiverBase.OnDataReceived(String data)


It looks like the header is being passed to the parser, not the JSON itself.

Bug or my configuration error?

How to disable header passing to parser?

Tested on ComfortClick v 4.9.36

Avatar
Jürgen Jürgenson

Hey

Try if: .TestData.Data1 works. Note the dot in front.

Avatar

Image 4628


not working :( same error.

Devices : 15.08.2023 16:37:59 : Error : Devices\Test\String : Error parsing received data. Unexpected character encountered while parsing value: P. Path , line 0, position 0. w Newtonsoft.Json.JsonTextReader.ParseValue()

Avatar
Jürgen Jürgenson
Quote from Krzysztof Szczepański

Image 4628


not working :( same error.

Devices : 15.08.2023 16:37:59 : Error : Devices\Test\String : Error parsing received data. Unexpected character encountered while parsing value: P. Path , line 0, position 0. w Newtonsoft.Json.JsonTextReader.ParseValue()

Have you tried different parser encodings too? Set it to none.

Avatar

Image 4629


not working :( same error. ( with and without dot in front ) 

Devices : 15.08.2023 20:48:14 : Error : Devices\Test\String : Error parsing received data. Unexpected character encountered while parsing value: P. Path , line 0, position 0. w Newtonsoft.Json.JsonTextReader.ParseValue()

Avatar
Jürgen Jürgenson
Quote from Krzysztof Szczepański

Image 4629


not working :( same error. ( with and without dot in front ) 

Devices : 15.08.2023 20:48:14 : Error : Devices\Test\String : Error parsing received data. Unexpected character encountered while parsing value: P. Path , line 0, position 0. w Newtonsoft.Json.JsonTextReader.ParseValue()

Well then im out of ideas. I made a similar test with postman and it works for me. Http-postman mock api test.bos

Avatar

Maybe it works because you are using a different device in Comfortclick. I use Basic, you use HTTP :)

Image 4631

my test file : Basic-Test.bos

Avatar
Jürgen Jürgenson
Quote from Krzysztof Szczepański

Maybe it works because you are using a different device in Comfortclick. I use Basic, you use HTTP :)

Image 4631

my test file : Basic-Test.bos

Test (demo).bos

Here is another demo for you - used udp sender and receiver with basic driver.

Does this work for you then? 

I know i used http - i wasnt sure why you used basic driver in the first place. Not sure tcp server works like that, but http does work.

Avatar

I am supposed to receive POST information in JSON from an external system. They make a blind call to the address and port I give them. I have the key in the header and the rest of the information in JSON.

I got around the decoding with regex, but the next issue came up with HTTPS. Comfortclick returns encoded information and I don't know how to get around it :(

Avatar
Jürgen Jürgenson
Quote from Krzysztof Szczepański

I am supposed to receive POST information in JSON from an external system. They make a blind call to the address and port I give them. I have the key in the header and the rest of the information in JSON.

I got around the decoding with regex, but the next issue came up with HTTPS. Comfortclick returns encoded information and I don't know how to get around it :(

Well you need to wait for CC support then. I tested the basic tcpserver and i got no response from it either. 
If you have a set ip for it does http driver get any values from it?

Avatar

I have everything configured as in the file I exported. Postman is installed locally and when sending http, data reaches Comfortclick without any problems, both in http and https.

This is what it looks like:

http:

Image 4636

https:

Image 4635

Now I have two problems:
1. JSON parsing doesn't work - probably due to passing header to parser, workaround is regex
2. TCPServer does not decrypt https connections

Thanks for your help, but I guess the problems lie deeper in CC.
I am waiting for their support :)