check object json

Moderator: leecollings

Post Reply
david31
Posts: 11
Joined: Thursday 07 January 2016 11:32
Target OS: Linux
Domoticz version: 3.8153
Contact:

check object json

Post by david31 »

Hello

I would if it's possible to test if an object exist on response json

Code: Select all

{
"tickets": [],
"links": [],
"disruptions": [],
"notes": [],
"feed_publishers": [],
"context": {
"timezone": "Europe/Paris",
"current_datetime": "20180402T213237"
},
"error": {
"message": "no solution found for this journey",
"id": "no_solution"
},
"exceptions": []
}
When no data, the field error exist
when data exist, the field error don't exist

i have test

Code: Select all

jsonLocation.error.id == "no_solution"
but i have

Code: Select all

[string "commandArray = {} ..."]:43: attempt to index field 'error' (a nil value)
when the field don't exist
david31
Posts: 11
Joined: Thursday 07 January 2016 11:32
Target OS: Linux
Domoticz version: 3.8153
Contact:

Re: check object json

Post by david31 »

i have found this and it work fine

Code: Select all

string.match(jsondevices, "error", 1)
Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot] and 1 guest