Hello,
I work on a project of communication between an application android and a Smartapp.
My application sends through an Https request a JSon of type:
{
“ROOM0”: {
“Name”: “kitchen”
“Device1”: "thermos3"
“Device0”: “Thermos4”
}
“Room1”: {
“Name”: “livingroom”
“Device1”: "thermos2"
“Device0”: “thermos1”
}
}
I can recover the JSon Room0 and Room1 sparse, but I can not retrieve each element of my JSon afterwards.
My code:
mappings {
path("/allheat") { action: [ GET: “heatDevises” ]}
path("/changeheat") { action: [ POST: “sendHeatCommands” ]}
path("/listRoom") { action: [ POST: “listRoomGet” ]}
Fonction:
def listRoomGet() {
debug(“listRoomGet called”)
def Room01 = request.JSON?.Room0
def Room02 = request.JSON?.Room1
def results = [ :]
results << [name1 : Room01] //{"Name": "kitchen","Device1": "thermos3","Device0": "Thermos4"}
results << [name2 : Room02] //{"Name": "living","Device1": "thermos2","Device0": "Thermos1"}
/*
def nameR = Room01.JSON?.Name
results << [name : nameR]
*/
render contentType: "text/json", data: new JsonBuilder(results).toPrettyString()
}
How can I recover my items separately?