Forum Discussion

MadmanDavid's avatar
9 years ago

ParseJSON inside a Task cannot parse long numbers

I'm trying to parse some timestamps from our server inside a Task and having trouble with long numbers. 

The numbers output from ParseJSON() are "invalid" 

If I use ParseJSON() within the main thread, the Roku has no issue with outputting the correct value.


// Example JSON string
{
    "pin": "8RY2",
    "pinKey": "2589b22c-240d-4a02-8a7f-8ddf2b273b73",
    "expiry": 1484795032530, // This long value (13 numbers) is output as invalid when converting to an AA
    "expired": false
}

// ParseJSON()
{
expired: false
expiry: invalid 'This should be the above value.
pin: "8RY2"
pinKey: "2589b22c-240d-4a02-8a7f-8ddf2b273b73"
}

I'm pretty sure this is not working as intended...

If I shorten the number by 4 digits, it quite happily parses.

4 Replies

  • On further investigation its not the Task specifically that cannot parse a long value. The passing of the AA back into the scene thread is what causes the issue.
  • "MadmanDavid" wrote:
    On further investigation its not the Task specifically that cannot parse a long value. The passing of the AA back into the scene thread is what causes the issue.

    Aha! Exactly what i guessed reading your first message.
    Yes, because `long` is unsupported by RSG data type. See the list of supported field types, strategically hidden here <interface>-Attributes ? Everything that is not one of them gets stripped during data cloning. `Long` is not one of them, so...
  • Okay. Good to know there's a layer that can posibly mangle attributes. I'll have to keep that in mind.
  • "MadmanDavid" wrote:
    Okay. Good to know there's a layer that can posibly mangle attributes. I'll have to keep that in mind.

    That will happen every time data has to cross boundaries between threads, be it main and render or task and render - a deep copy is made of it and "unsupported" types are silently(!) lopped off. There are somewhat complicated rules which thread owns what objects, so beware it may not be obvious when