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


Question

Posted

Hello guys

I have a Json response to an http command that will give me alot of info.

The command is:

Please login or register to see this link.

What i get is:

{

"SourceID": 0,

"QueueCount": 54,

"QueueSongIndex": 14,

"ChangeQueueID": 2,

"ChangeSlideShowID": 1,

"ChangeMetaDataID": 61,

"Status": 2,

"Controls": 51642623,

"RepeatMode": 0,

"ShuffleMode": false,

"CurrSong": {

"Flags": 12289,

"ID": "72a0263645a710284dfce03c3474d15f",

"Title": "Khalik Fakirney",

"Type": 32768,

"ArtworkURI": "http://192.168.1.215:10243/WMPNSSv4/2524841952/0_ezNDNDg4M0VELTBCMDktNDM5OS1BMDZGLUU0NTIzNzIxNUVGN30uMTQuM0I2QkUxQ0U.jpg?albumArt=true",

"Album": "Best of",

"Artists": "Amr Diab",

"Duration": 209,

"Genres": "Other",

"Released": "2009",

"Track": "15",

"BitRate": 176400,

"ListenerCount": 0,

"Rating": 75,

"TotalItems": 0,

"DisplayInfo": [

"Khalik Fakirney",

"Amr Diab",

"Best of",

"Other - 2009"

]

},

"NextSong": {

"Flags": 12289,

"ID": "07b03113edf1322f47bbff2af0a698d8",

"Title": "A3'eb A3'eb",

"Type": 32768,

"ArtworkURI": "http://192.168.1.215:10243/WMPNSSv4/2524841952/0_ezkzNUEzN0FGLUNFQ0YtNDQ4RS1CRTBBLUU0N0Q3NTEyNDJDNX0uMTUuM0I2QkUxQ0U.jpg?albumArt=true",

"Album": "Best of",

"Artists": "Amr Diab",

"Duration": 211,

"Genres": "Other",

"Released": "2009",

"Track": "16",

"BitRate": 176400,

"ListenerCount": 0,

"Rating": 75,

"TotalItems": 0,

"DisplayInfo": [

"A3'eb A3'eb",

"Amr Diab - Best of"

]

},

"CurrProgress": 176,

"SlideShowAvailable": false,

"SearchPromptText": "Search for music by artist, album, or title",

"SourceLockedByZoneID": -1

}

I just want to take the Title and the Album name for example and add them to a label in a Virtual device in HC2

Is there anyway to do so?

7 answers to this question

Recommended Posts

  • 0
Posted

yes, read how to do that in virtual device

how to get json

Please login or register to see this link.

and how to use json

Please login or register to see this link.

  • 0
  • Inquirer
  • Posted

    Thank you

    Yes Actually i have tried that

    json.decode(response)

    But how to proceed after that?

    HC22 = Net.FHttp("192.168.1.215",8735)

    response = HC22:GET("/api/v1/zones/0/nowplaying")

    jsonTable = json.decode(response)

    local Artist = jsonTable.Title

    fibaro:call(889,"setProperty","ui.Label1.value",Artist)

    fibaro:sleep(5000);

    • 0
    Posted

    Use that

    Please login or register to see this link.

    from there you will easer saw structure of json Title is under CurrSong

    Please login or register to see this code.

    • 0
  • Inquirer
  • Posted

    Thanx it worked

    Please login or register to see this image.

    /emoticons/default_biggrin.png" alt=":D" srcset="https://forum.fibaro.com/uploads/emoticons/[email protected] 2x" width="20" height="20" />

    • 0
    Guest berga_s
    Posted

    Hi A.Socha,

    I'm tring to get the value stringForecast = jsonTable.forecast.txt_forecast.forecastday(0).fcttext_metric

    from the json string below using the json online editor to understand the structure.

    May be the sintax of forecastday(0) is not correct. What I'm wrong?

    Is there the possibility to print out the structure and values of jsonTable I've created with json.decode() function?

    thanks

    [ Added: 2014-09-19, 12:41 ]

    OK, solved!

    the right string is:

    stringForecast = jsonTable.forecast.txt_forecast.forecastday[1].fcttext_metric

    Use [] instead of () and the first value is 1 and not 0 as shoved by online editor...

    • 0
    Posted

    Hi berga_s,

    Yes, as you have discovered, in Lua, the default indexing of tables starts at 1, not 0.

    The code I just posted

    Please login or register to see this link.

    shows the correct key number if it will help you in the future.

    Adam Bewsher

    • 0
    Guest berga_s
    Posted

    Thanks a lot Adam!!!

    Very useful examples.

    Please login or register to see this image.

    /emoticons/default_icon_wink.gif" alt=";-)" />

    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...