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

Decode JSON with SPACE char


Martin_N
 Share

Question

Dears colleagues,
I need help please.
I'm preparing a plugin for iEAST and I ran into one error decoding the JSON table. These are embedded spaces in the code. Can I modify this so that I can use the standard parser? In the figure, gaps are marked with red dots. Thank you very much.

eM.

 

Please login or register to see this attachment.

 

Edited by Martin_N
Link to comment
Share on other sites

6 answers to this question

Recommended Posts

  • 0
  • Inquirer
  • Maybe the problem is something else.
    I'm working on the idea that there is a problem with "" - zero value.
    I found some mentions here: 

    Please login or register to see this link.

    //----------------------------------------------------------------------------------------------

    // from this website:

    Please login or register to see this link.

    //

    Handling of empty arrays

    Please login or register to see this code.

     

    • cmj-JSON4Lua: does not work correctly (empty arrays are encoded as simple empty tables)
    • dkjson: works correctly (uses a "type field" on the metatable)
    • Fleece: not tested
    • jf-JSON: optionally works correctly; by default empty tables are always encoded as empty objects
    • Lua-Yajl: does not work correctly (empty tables are encoded as empty arrays, always)
    • mp-CJSON: does not work correctly (empty tables are encoded as empty objects, always)
    • sb-Json: not tested
    • th-LuaJSON: (v1.3) works (assigns a special metatable to arrays)
    • luci.json: decodes to nil, empty tables are encoded as empty arrays, always
    • lunajson: works correctly if the decoder is passed the option to embed array length.

    //----------------------------------------------------------------------------------------------

    In the picture is a cause ...maybe.

    I get some values in the Json table:

     "ali_uuid"  ""
     "dsp_ver"  ""
     "essid"  ""

     "silenceOTATime"

     

    Is it possible?? Can it be solved?

     

     ""  

     

     

     

    Please login or register to see this attachment.

     

    Maybe is a problem with length? In the table is a 81 items.

     

    Thanks, eM.

     

    Edited by Martin_N
    Link to comment
    Share on other sites

    • 0
  • Inquirer
  • I found a problem with JSON decoding on my iEAST device.
    The problem is the escape character. It appears in two places in the JSON table.

    Is a different in the showing Response and the Preview mode.

     

    Please login or register to see this attachment.

     

     

    Please login or register to see this attachment.

     

    So I was wondering, what if the problem is in the different interpretation in the scene and in QuickApp?

    When I put data table in to LUA scene and if i try decode this, i get response:

    >>[13.06.2020] [22:11:54] [ERROR] [SCENE84]: (load):16: invalid escape sequence near ''{ "language": "en_us", "ssid": "iEAST_F4AD", "hideSSID": "1", "SSIDStrategy": "2", "firmware": "4.2.8230", "build": "release", "project": "iEAST-01", "priv_prj": "iEAST-01", "Release": "20200430", "branch": "stable\/'

     

    The char od escape "\"
    Note: It is not possible to decode this JSON table in a LUA scene.
    In QuickApp it is possible :)

     

    Why?

     

    eM.

     

     

    Link to comment
    Share on other sites

    • 0
    59 minutes ago, Martin_N said:

    I found a problem with JSON decoding on my iEAST device.
    The problem is the escape character. It appears in two places in the JSON table.

    Is a different in the showing Response and the Preview mode.

     

    Please login or register to see this attachment.

     

     

    Please login or register to see this attachment.

     

    So I was wondering, what if the problem is in the different interpretation in the scene and in QuickApp?

    When I put data table in to LUA scene and if i try decode this, i get response:

    >>[13.06.2020] [22:11:54] [ERROR] [SCENE84]: (load):16: invalid escape sequence near ''{ "language": "en_us", "ssid": "iEAST_F4AD", "hideSSID": "1", "SSIDStrategy": "2", "firmware": "4.2.8230", "build": "release", "project": "iEAST-01", "priv_prj": "iEAST-01", "Release": "20200430", "branch": "stable\/'

     

    The char od escape "\"
    Note: It is not possible to decode this JSON table in a LUA scene.
    In QuickApp it is possible :)

     

    Why?

     

    eM.

     

     

     

    Could you print out the whole json string (the string version without trying to decode it) in the scene or quickApp log window? and post it here.

    It's difficult to see what can be wrong from the cutoff screen dump version.

    I believe that its your web console that quotes the '/' in the second log and it's not part of what you get from the device.

    Link to comment
    Share on other sites

    • 0
  • Inquirer
  • Here is a report from QuickApp.

     

    [14.06.2020] [00:14:48] [DEBUG] [QUICKAPP254]: { "language": "en_us", "ssid": "iEAST_F4AD", "hideSSID": "1", "SSIDStrategy": "2", "firmware": "4.2.8230", "build": "release", "project": "iEAST-01", "priv_prj": "iEAST-01", "Release": "20200430", "branch": "stable\/wiimu-4.2", "group": "1", "master_uuid": "FF310009A639428523EE2800", "master_ip": "192.168.10.31", "slave_interface": "2", "slave_mask": "0", "expired": "0", "internet": "1", "uuid": "FF310009B34C8494BA3816AA", "MAC": "00:22:6C:05:F4:AD", "STA_MAC": "00:22:6C:05:F4:AF", "CountryCode": "CN", "CountryRegion": "1", "date": "2020:06:13", "time": "22:14:48", "tz": "2.000000", "dst_enable": "1", "netstat": "0", "essid": "", "apcli0": "0.0.0.0", "eth2": "192.168.10.32", "eth_dhcp": "1", "hardware": "A31", "VersionUpdate": "0", "NewVer": "0", "mcu_ver": "2", "mcu_ver_new": "0", "dsp_ver_new": "0", "ra0": "10.10.10.254", "temp_uuid": "51ED823DAFF06EF8", "cap1": "0x185200", "capability": "0x286809c0", "languages": "0x6", "dsp_ver": "", "streams_all": "0x7ffffffe", "streams": "0x7ffffffe", "region": "unknown", "external": "0x0", "preset_key": "6", "plm_support": "0x2", "spotify_active": "0", "lbc_support": "0", "WifiChannel": "11", "RSSI": "0", "battery": "0", "battery_percent": "0", "securemode": "1", "auth": "WPAPSKWPA2PSK", "encry": "AES", "psk": "4150496A4443433376726D503130717564E5248306D4B643873354671692F457977544A4834487A335A514A6B73744857646363336859764976376E537370544C534A357A356444592F464741513536596275773D3D", "ali_pid": "SoundStream", "ali_uuid": "", "iot_ver": "1.0.0", "upnp_version": "1005", "upnp_uuid": "uuid:FF310009-B34C-8494-BA38-16AAFF310009", "uart_pass_port": "8899", "communication_port": "8819", "web_firmware_update_hide": "0", "web_login_result": "-1", "ignore_talkstart": "0", "silenceOTATime": "", "ignore_silenceOTATime": "1", "new_tunein_preset_and_alarm": "1", "iheartradio_new": "1", "new_iheart_podcast": "1", "security": "https\/2.0", "security_version": "2.0", "privacy_mode": "0", "user1": "266:524", "user2": "1396:2097", "DeviceName": "Obyvak", "GroupName": "Obyvak" }

     

    Here is the message from the scene - the first escape stops the scene

    [14.06.2020] [00:15:37] [ERROR] [SCENE84]: (load):17: invalid escape sequence near ''{ "language": "en_us", "ssid": "iEAST_F4AD", "hideSSID": "1", "SSIDStrategy": "2", "firmware": "4.2.8230", "build": "release", "project": "iEAST-01", "priv_prj": "iEAST-01", "Release": "20200430", "branch": "stable\/'

     

    When I remove first ecape char, second ecape stops the scene too.

     

    [14.06.2020] [00:16:38] [ERROR] [SCENE84]: (load):17: invalid escape sequence near ''{ "language": "en_us", "ssid": "iEAST_F4AD", "hideSSID": "1", "SSIDStrategy": "2", "firmware": "4.2.8230", "build": "release", "project": "iEAST-01", "priv_prj": "iEAST-01", "Release": "20200430", "branch": "stable/wiimu-4.2", "group": "1", "master_uuid": "FF310009A639428523EE2800", "master_ip": "192.168.10.31", "slave_interface": "2", "slave_mask": "0", "expired": "0", "internet": "1", "uuid": "FF310009B34C8494BA3816AA", "MAC": "00:22:6C:05:F4:AD", "STA_MAC": "00:22:6C:05:F4:AF", "CountryCode": "CN", "CountryRegion": "1", "date": "2020:06:13", "time": "19:23:37", "tz": "2.000000", "dst_enable": "1", "netstat": "0", "essid": "", "apcli0": "0.0.0.0", "eth2": "192.168.10.32", "eth_dhcp": "1", "hardware": "A31", "VersionUpdate": "0", "NewVer": "0", "mcu_ver": "2", "mcu_ver_new": "0", "dsp_ver_new": "0", "ra0": "10.10.10.254", "temp_uuid": "51ED823DAFF06EF8", "cap1": "0x185200", "capability": "0x286809c0", "languages": "0x6", "dsp_ver": "", "streams_all": "0x7ffffffe", "streams": "0x7ffffffe", "region": "unknown", "external": "0x0", "preset_key": "6", "plm_support": "0x2", "spotify_active": "0", "lbc_support": "0", "WifiChannel": "11", "RSSI": "0", "battery": "0", "battery_percent": "0", "securemode": "1", "auth": "WPAPSKWPA2PSK", "encry": "AES", "psk": "4150496A4443433376726D503130717564E5248306D4B643873354671692F457977544A4834487A335A514A6B73744857646363336859764976376E537370544C534A357A356444592F464741513536596275773D3D", "ali_pid": "SoundStream", "ali_uuid": "", "iot_ver": "1.0.0", "upnp_version": "1005", "upnp_uuid": "uuid:FF310009-B34C-8494-BA38-16AAFF310009", "uart_pass_port": "8899", "communication_port": "8819", "web_firmware_update_hide": "0", "web_login_result": "-1", "ignore_talkstart": "0", "silenceOTATime": "", "ignore_silenceOTATime": "1", "new_tunein_preset_and_alarm": "1", "iheartradio_new": "1", "new_iheart_podcast": "1", "security": "https\/'

     

    But, now I need this function only in the QuickApp...

    Now I'm just interested in not having a problem with the next update in the future.

    Thanks to JGAB

    Edited by Martin_N
    Link to comment
    Share on other sites

    • 0
    This works in a HC3 scene:

    Please login or register to see this code.

    \/ is a valid escape sequence in json expressions (\/ becomes /)  and are parsed correctly by the json parser (both scenes and QAs)

    However, if you include a Lua string literally in your code with \/ is not a valid escape sequence (\n \r etc are) and  you get an error.

    Take away: Lua and json have slightly different valid escape sequences.

     

    Try

    Please login or register to see this code.

    This gives an error. That it is the Lua parser that gives you the error when it tries to load the scene code you can see on the error message (load)

    [14.06.2020] [00:15:37] [ERROR] [SCENE84]: (load):17: invalid escape sequence near 

    So the problem is not the json parser but that you have included the string literally in your code to test it.

    There is a Lua multi line string format [[ ... ]] that doesn't look for escape sequences inside the string and it works.

    Please login or register to see this code.

    but also prints "\/a"

     

    Btw,

    Please login or register to see this code.

    also crashes a QA.

     

    So, if you need to include the string for test in your code define it with [[ .. ]] like in my example.

    However, I guess you receive the string from an http request and send it to json.decode so it should not be a problem?

    Or is it so that you have constant strings in your code that you send to the device that include \/ ? In that case use [[ .. ]] or just replace \/ with /

     

     

     

    Edited by jgab
    • Thanks 1
    Link to comment
    Share on other sites

    • 0
  • Inquirer
  • Thank you JGAB.
    I know that it works in QA. I didn't realize the problem of inserting a string in a scene.

    That's the way it is at night ... :oops: I panicked.
    Note: the problem was actually somewhere else, why I did not get the result from decoding in QA (I overlooked one condition that returned me only the status, but not the result).

    Your contribution is definitely valuable. In the future, this "blind track" will also help others. One is still learning ..

    eM.

    Link to comment
    Share on other sites

    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.

     Share

    ×
    ×
    • Create New...