http basic string manipulation

Avatar
  • updated
  • Answered

Hi There,


Usinng the Http basic I can bring a string back from an API to another device, but that string contains data I do not need, I only want the present value from this response: {"present-value":22.285308837890625,"object-id":"0.1001","object-instance":"1001","object-type":"0","device-id":"0","href":"http://192.168.0.100:47800/api/v1/bacnet/devices/0/objects/0.1001"}


Is this possible in Comfort Clik, in short I wanto to populate a temperature in comfort click using the present value in the above response?


Thanks


How would you rate the customer service you received?

Satisfaction mark by Andy Gill 9 years ago

Add a comment about quality of support you received (optional):

Pinned replies
Avatar
ComfortClick ComfortClick
  • Answer

Hello,

it is possible to parse JSON and XML data from the response. If your response is in one of those formats it is quite easy to read out the data. Another way is to use REGEX and parse out any data from text, but that is harder.


Example for JSON:

{

"Sensor1": {
"Temperature": 10
}

}

On the main HTTP node chose parser type "Json"

If you would like to read out temperature from sensor 1 (value 10), create a new variable under HTTP node e.g. double and enter Sensor1.Temperature in the Token Name field.


Regards


Avatar
Fabien Fuster

Nice to read you could fix it Calin !

Avatar
Joachim O

Hijacking this thread.

I'm trying to get the 589 value from "duration_in_traffic" with token below:


rows[0].elements[0].duration_in_traffic.@value

Not having any luck.

JSON Response:

 

   "rows":[  
  {  
 "elements":[  
        {  
               "distance":{  
                  "text":"7.1 km",
                  "value":7073
               },
               "duration":{  
                  "text":"10 mins",
                  "value":595
               },
               "duration_in_traffic":{  
                  "text":"10 mins",
                  "value":589
               },
               "status":"OK"
            }
         ]
      }
   ],
   "status":"OK"
}

Suggestions anyone?

EDIT: removed the @. Worked like a charm :)