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

json.decode - Need to escape characters but can't get it working.


Question

Posted (edited)

So I'm trying to pull a pice of information from a json reply but I need to either use [0] or .. in the string, both of which will not work. I've tried escaping them with a "\" but they still fail.

 

The line can either be response[0].id or response..id

 

This is the entire string...

Please login or register to see this code.

 

Any ideas?

Edited by Desmo

8 answers to this question

Recommended Posts

  • 0
Posted
4 minutes ago, Desmo said:

So I'm trying to pull a pice of information from a json reply but I need to either use [0] or .. in the string, both of which will not work. I've tried escaping them with a "\" but they still fail.

 

The line can either be response[0].id or response..id

 

Any ideas?

 

Can you post the json string?

  • 0
  • Inquirer
  • Posted (edited)

    Just edited post to include the entire string :)

     

    It's the first "id" in the string I need.

    Edited by Desmo
    • 0
    Posted
    7 minutes ago, Desmo said:

    Just edited post to include the entire string :)

     

    It's the first "id" in the string I need.

     

    Please login or register to see this code.

     

    • 0
  • Inquirer
  • Posted

    OK, that works in the sample but how do I get the double [[ & ]] to each side of my response?

     

    Here is my code (with some details extracted)

    Please login or register to see this code.

    It's the "response.data" I need to collect and add the double square brackets to. I had a quick go but nothing was working.

     

    Thanks again.

    • 0
    Posted
    1 hour ago, Desmo said:

    OK, that works in the sample but how do I get the double [[ & ]] to each side of my response?

    Here is my code (with some details extracted)

    It's the "response.data" I need to collect and add the double square brackets to. I had a quick go but nothing was working.

    Thanks again.

     

    The [[..]] is just a multi-line string quote.

    We could do just

    Please login or register to see this code.

    This (the 'str') is what you get in your response handler

    Please login or register to see this code.

     

    • 0
  • Inquirer
  • Posted

    This is so strange....I'm absolutely sure that's what I had before but obviously not. I was on the right track but obviously had the syntax slightly wrong somewhere so thanks for tidying that up. Just one remaining problem now...the result is a little odd.

     

    The json result shows this...

    34646001298457174

     

    But it's turned in to this when I pull it out from the result...

     3.4646001298457e+16

    • 0
    Posted
    8 minutes ago, Desmo said:

    This is so strange....I'm absolutely sure that's what I had before but obviously not. I was on the right track but obviously had the syntax slightly wrong somewhere so thanks for tidying that up. Just one remaining problem now...the result is a little odd.

     

    The json result shows this...

    34646001298457174

     

    But it's turned in to this when I pull it out from the result...

     3.4646001298457e+16

    Its the same value, just different printed representations.

    If you print it with 

    Please login or register to see this code.

     

    • 0
  • Inquirer
  • Posted

    I still couldn't get the "id" working but found that "id_s" has the same value and works fine so I'm all set up.

    Thanks for your help with this @jgab :>

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