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

Get namefiles from http request?


Question

Posted

When I do a http request in lua I get this response:

[{"name":"VOLUMEID ","size":"0","attributes":"8","timestamp":"4352"},{"name":"UserVar.txt","size":"824","attributes":"32","timestamp":"29306"},{"name":"index.htm","size":"3047","attributes":"32","timestamp":"29306"},{"name":"index.js","size":"4579","attributes":"32","timestamp":"29306"},{"name":"jquery.js","size":"-32701","attributes":"32","timestamp":"29306"},{"name":"logo.png","size":"-21568","attributes":"32","timestamp":"29306"},{"name":"success.html","size":"135","attributes":"32","timestamp":"29306"},{"name":"jquery.mobile.css","size":"13492","attributes":"32","timestamp":"29306"},{"name":"jquery.mobile.js","size":"-23698","attributes":"32","timestamp":"29306"},{"name":"icons-18-white.png","size":"1829","attributes":"32","timestamp":"29306"},{"name":"ajax-loader.gif","size":"6559","attributes":"32","timestamp":"29306"},{"name":"json2.js","size":"1222","attributes":"32","timestamp":"29306"}]

How do I get the filenames in a table in Lua. If I use json.decode I got strange strings back like "table: 0x8dea490"..

Please login or register to see this image.

/emoticons/default_icon_eek.gif" alt=":shock:" />

Please help....

4 answers to this question

Recommended Posts

  • 0
Posted

Lambik, try this

Please login or register to see this code.

OUTPUT:

Please login or register to see this code.

Please login or register to see this image.

/emoticons/default_icon_smile.gif" alt=":-)" />

  • 0
  • Inquirer
  • Posted

    Please login or register to see this code.

    Wow!

    Please login or register to see this image.

    /emoticons/default_icon_eek.gif" alt=":shock:" />

    Can you explain what this is doing? I want to learn!

    Please login or register to see this image.

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

    Thanx anayway!

    • 0
    Posted

    Lambik,

    Please login or register to see this image.

    /emoticons/default_icon_biggrin.gif" alt=":-D" />

    Please login or register to see this code.

    decode json data or return empty object if null data

    Please login or register to see this code.

    - loop in main object (table) (with pairs or ipairs as you want here)

    - k for key and v for value, in your example the value = table (you can check with lua type(v))

    - v['name'] to access 'name', you can v['size'] etc...

    • 0
  • Inquirer
  • Posted

    Krikroff Thumbs up for the explanation! I think I understand... Well, I trying to.... Had to read and look several times....

    Please login or register to see this image.

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

    Found some further explanation on the for loop on

    Please login or register to see this link.

    Thanx again Krikroff. I noticed I have still a lot to learn....

    Please login or register to see this image.

    /emoticons/default_icon_mrgreen.gif" alt=":mrgreen:" />

    [ Added: 2014-08-31, 14:43 ]

    The code is used for my iTach checker Virtual Device:

    Please login or register to see this link.

    You are mentioned in the thanks-list...

    Please login or register to see this image.

    /emoticons/default_icon_smile.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...