Page 1 of 1

Decode JOSN Sting

Posted: Thursday 01 November 2018 19:36
by jannnfe
Hey,
I have a string like this:

Code: Select all

{"b":122,"cw":0,"g":128,"m":3,"r":255,"t":0,"ww":0}
How can I get the r, g and b value from that string?
I like to write a script that catches the RGB from Virtual Device Color picking and send it over Http to my ESPEasy firmware.
I already managed to get the Color Values from device.

Thanks :)

Re: Decode JOSN Sting

Posted: Thursday 01 November 2018 23:20
by waaren
jannnfe wrote: Thursday 01 November 2018 19:36 I have a string like {"b":122,"cw":0,"g":128,"m":3,"r":255,"t":0,"ww":0}
How can I get the r, g and b value from that string?
This should do it

Code: Select all

-- getJSON
  
return {
    on      =       {   timer = { "every minute"  }},    
    
    execute = function(dz)
    
        colorTable = dz.utils.fromJSON('{"b":122,"cw":0,"g":128,"m":3,"r":255,"t":0,"ww":0}')
    
        print ("b:  " .. colorTable.b)
        print ("cw: " .. colorTable.cw)
        print ("g:  " .. colorTable.g)
        print ("m:  " .. colorTable.m)
        print ("r:  " .. colorTable.r)
        print ("t:  " .. colorTable.t)
        print ("ww: " .. colorTable.ww)
       
    end
}

Re: Decode JOSN Sting

Posted: Thursday 01 November 2018 23:25
by jannnfe
You are the best. Thank you very much I did not think about the dzVents utils. Many Thanks :)