- Thu Dec 07, 2017 9:07 am
#72382
data = '{"notifications":[{"recipient":2,"sender":1,"id":2,"date":"2017-11-27 22:43:21","status":"new"}]}'
ok, tablet_json = pcall(sjson.decode, data) -- that is more correct
if ok then
--[[
tablet_json = {table [array {table}]}
array starting point from 1
]]--
print(tablet_json.notifications[1].recipient) -- get value recipient = 2
--or
print(tablet_json['notifications'][1]['recipient'])
print(tablet_json.notifications[1].date) -- get value date = 2017-11-27 22:43:21
for key,value in pairs(tablet_json.notifications[1]) do -- get all tablet key and value
print(key,value)
end
else
print("failed to encode!")
end
tablet_json.notifications[1].recipient = 2017
json_string = sjson.encode(tablet_json)
print(json_string) --{"notifications":[{"recipient":2017,"sender":1,"id":2,"date":"2017-11-27 22:43:21","status":"new"}]}