Json question

Tagged: 

This topic contains 5 replies, has 3 voices, and was last updated by  Ethernaut 2 years, 3 months ago.

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #6406

    Ethernaut
    Participant

    Consider this json file:

    And this M2 code to read it:

    I want to iterate through each of the animation clips in the json file and print their values, just for this test.

    Is there a cleaner way to access the iterator? Can I get rid of all that casting and get the correct type (JsonObject) out of the gate? JsonObject.All is not working for me, I get the “Iterator has no ‘AtEnd’ property” error.

    #6408

    codifies
    Participant

    can’t see most of your code, not sure what you’re trying to improve…??

    #6409

    Ethernaut
    Participant

    1.I’m trying to get rid of the casting. Is there a way to iterate the JsonObjects directly, instead of JsonValues? Which led me to…

    2.I was wondering if there’s something wrong with JsonObject.All. I get an error when I try to use it instead of JsonObject.ToObject() (which returns a map)

    Thanks.

    #6411

    peterigz
    Participant

    I use ToString/ToNumber etc. Here’s a snippet from a json loader I’m using if it helps:

    And the json file for reference:

    #6413

    codifies
    Participant
    [/crayon]

    I wonder if these couldn’t be done with reflection, ie the jason property name provides the variable name thats looked up and used via reflection, but mind you this could potentially cause a security issue…

    #6419

    Ethernaut
    Participant

    Thanks, that is helpful. This looks a bit more neat.

    I had t add the line “Local obj := c.Value.ToObject()” which essentially casts the JsonValue as an object, so functionally it’s not that different, but it’s easier to read.

Viewing 6 posts - 1 through 6 (of 6 total)

You must be logged in to reply to this topic.