Jump to content

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


  • 0

Question

Posted

Hello,

 

I want to decode a JSON file with format

Please login or register to see this code.

Example : I want to print the temperature (28) with fibaro:debug

 

local name = ?????

fibaro:debug(name)

 

ThC

 

Have you an idea to do that ?

 

Thank you in advance.

2 answers to this question

Recommended Posts

  • 0
Posted

I'am not a proff but I do think when ever you have an    [    you also need it to close with:   ]

but i can be wrong :) 

 

local text = '{"name":"ThC","date":"2020-04-25T11:27:55.000Z","temperature":28,"zz":"6.2","xxx":698,"zzz":"4.1"}'
local textjs = json.decode(text)
local name = textjs.name
print(name)
  • 0
Posted
2 hours ago, dexxlab said:

Hello,

I want to decode a JSON file with format

Please login or register to see this code.

Example : I want to print the temperature (28) with fibaro:debug

local name = ?????

fibaro:debug(name)

 

@Sagittarius is right, there is a ']' missing to close the array, but maybe your example was just a piece of the json string?

Assume your json string is:

Please login or register to see this code.

This tells us that the json struct is {user : <array of itmes>}

so if we do

Please login or register to see this code.

we get the json table

Please login or register to see this code.

to print out the first name you can then do

Please login or register to see this code.

or to print out all names assuming the array contains more than one item.

Please login or register to see this code.

 

  • Like 1

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...