Help with Web Services - JSON on Response


(Jonathan Rivera) #1


I’m having an issue with a web services app i’m playing around with. I’m able to hit the end point and get a list of my switches and their values but the information seems to be received in a string instead of a JSON (although the switch information is placed into a JSON format.

So here’s what I have in my SmartApp

mappings {
 path("/switches") {
    action: [
      GET: "listSwitches"
  path("/switches/:command") {
  action: [
  PUT: "updateSwitches"

//Returns a list like
// [[name: "kitchen lamp", value:"off"], [name: "bathroom", value: "on"] ] 
def listSwitches(){
def resp = []
    switches.each {
      resp << [name: it.displayName, value: it.currentValue("switch")]
    return resp

and the response i’m receiving from SmartThings looks like this:

{"statusCode":200,"body":"[{\"name\":\"Patio Lights\",\"value\":\"off\"},{\"name\":\"Living Room Switch\",\"value\":\"on\"},{\"name\":\"Kitchen Dimmer\",\"value\":\"off\"},{\"name\":\"Hallway Light\",\"value\":\"off\"},{\"name\":\"Entry Door Light\",\"value\":\"off\"}]"

Is this the correct format that the SmartApp should be sending the information? The only way i’m able to access this information on my server side is by parsing the string. I’m not able to access each switch as an object.

Any help would be appreciated! Just looking to make sure that my smartapp is sending the information correctly.