Welcome to Smart Home Forum by FIBARO
Dear Guest,
as you can notice parts of Smart Home Forum by FIBARO is not available for you. You have to register in order to view all content and post in our community. Don't worry! Registration is a simple free process that requires minimal information for you to sign up. Become a part of of Smart Home Forum by FIBARO by creating an account.
As a member you can:
- Start new topics and reply to others
- Follow topics and users to get email updates
- Get your own profile page and make new friends
- Send personal messages
- ... and learn a lot about our system!
Regards,
Smart Home Forum by FIBARO Team
Question
Jay Ess 5
Hi I am trying to encode the bank holdiays for the year, I have managed to get a list of holidays from calendrific.com and get this as my return
[{'name':New Year's Day','date':2021-01-01','name':Good Friday','date':2021-04-02','name':Early May Bank Holiday','date':2021-05-03','name':Spring Bank Holiday','date':2021-05-31','name':Christmas Day','date':2021-12-25','name':Boxing Day','date':2021-12-26','name':Substitute Bank Holiday for Christmas Day','date':2021-12-27','name':Substitute Bank Holiday for Boxing Day','date':2021-12-28'}]
The way i have got is as follows:
http:request(string.format(address),{options={headers={Accept="application/json"},method='GET'},
success = function(status)
local data = json.decode(status.data)
data = data.response.holidays
for _,d in ipairs(data) do
if cR == "" then
cR="[{'name':"..d.name.."','date':"..d.date.iso.."'"
else
cR=cR ..",'name':".. d.name.."','date':"..d.date.iso.."'"
end
--print (d.name)
--print(d.date.iso)
end
cR = cR.."}]"
--string.gsub(cR,"'",""")
print (cR)
end,
error = function(error) print(error) end
}
)
my problem is that in order to json encode it properly, from what I understand, I need all the single quotes to be double quotes, but i don't know how to get the data as double quotes,
any help would be great.
Many thanks.
Link to comment
Share on other sites
6 answers to this question
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.