HISE Logo Forum
    • Categories
    • Register
    • Login

    Parse JSON Question

    Scheduled Pinned Locked Moved Scripting
    9 Posts 3 Posters 312 Views
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • ?
      A Former User
      last edited by

      Howdy folks, I have a JSON object named after each Expansion and need to access it directly:

      {
      	  "Expansion" : 1.1,
      }
      

      Since it's a string, I can't do something like this:

      const myExpansion = expHandler.getCurrentExpansion();
      reg myExpansionName = myExpansion.getProperties().Name; // "Expansion"
      
      Console.print("Latest Version: " + myJSONObject.myExpansionName); //doesn't work because "Expansion" is a string
      

      Is there a variant of eval / parseInt / parseAsJSON for this? None of them seem to work for this particular case.

      1 Reply Last reply Reply Quote 0
      • d.healeyD
        d.healey
        last edited by

        Type parseJSON into the forum search ;)

        Libre Wave - Freedom respecting instruments and effects
        My Patreon - HISE tutorials
        YouTube Channel - Public HISE tutorials

        ? 1 Reply Last reply Reply Quote 0
        • ?
          A Former User @d.healey
          last edited by

          @d-healey I obviously need a t-shirt cause I still can't get it working.

          Is there any other way to just index JSON? I see examples of that on stackoverflow and since I already have all of the relevant indexes in a loop it would fix everything

          d.healeyD 1 Reply Last reply Reply Quote 0
          • d.healeyD
            d.healey @A Former User
            last edited by

            @iamlamprey Can you give an example that isn't working?

            Libre Wave - Freedom respecting instruments and effects
            My Patreon - HISE tutorials
            YouTube Channel - Public HISE tutorials

            ? 1 Reply Last reply Reply Quote 0
            • ?
              A Former User @d.healey
              last edited by

              @d-healey I think I might have it backwards with the whole Parse thing.

              I just need to take this:

              reg myString = "ExpansionName"; // i would get this from getProperties()
              
              const myObj = 
              {
              	  "ExpansionName" : 1.1,
              }
              

              and do this:

              Console.print(myObj.myString);
              
              Console.print(myObj.ExpansionName); // Works
              Console.print(myObj."ExpansionName"); // Doesn't work (obviously)
              

              So I need to remove the " " from the string somehow, the following all just return undefined so I think I'm looking in the wrong places:

              parseInt(myString ) // duh
              eval(myString)
              myString.ParseAsJSON();
              
              d.healeyD 1 Reply Last reply Reply Quote 0
              • d.healeyD
                d.healey @A Former User
                last edited by

                @iamlamprey It's an object. You can access properties either using . or using []

                Libre Wave - Freedom respecting instruments and effects
                My Patreon - HISE tutorials
                YouTube Channel - Public HISE tutorials

                ? 1 Reply Last reply Reply Quote 0
                • ?
                  A Former User @d.healey
                  last edited by

                  @d-healey Ahh there we go, I didn't try passing the string as an Index.

                  const myObj = 
                  {
                      "ExpansionName" : 1.0,
                  }
                  
                  const myString = "ExpansionName"
                  
                  Console.print(myObj[ExpansionName]);
                  

                  Cheers

                  1 Reply Last reply Reply Quote 1
                  • ?
                    A Former User
                    last edited by A Former User

                    btw how does const vs const var work? Is it just saving 3 keystrokes? Or is there something going on in the background that is more/less efficient?

                    Christoph HartC 1 Reply Last reply Reply Quote 0
                    • Christoph HartC
                      Christoph Hart @A Former User
                      last edited by

                      @iamlamprey just three keystrokes.

                      1 Reply Last reply Reply Quote 0
                      • First post
                        Last post

                      50

                      Online

                      1.7k

                      Users

                      11.7k

                      Topics

                      101.9k

                      Posts