Load text from JSON


(Dave) #1

Looking for a simple example of loading text & images from a json file. I’ve searched the forums a lot and nothing that was strictly just that.

For example I’d like to load the following json. Let’s call it animation-text.json.

{
    "mydata" : {
        "block-a" : {
            "text-1" : {
              "option-0": "Dude",
              "option-1": "Awesome",
              "option-2": "Bogus",
              "option-3": "WTF",
              "option-4": "Strange"
            },
            "title" : "Click bait stinks",
            "subtitle" : "I've got nothing!"
        },
        "block-b" : {
            "text-1" : {
              "option-0": "Dude",
              "option-1": "Awesome",
              "option-2": "Bogus",
              "option-3": "WTF",
              "option-4": "Strange"
            },
            "title" : "Thought of something new",
            "subtitle" : "Still have nothing.",
            "graphic" : "./images/fielname.png"
        }
    }

}

Then how would I apply values to different elements?

If someone could share an example file, that would be of huge help. I do well with reverse engineering.


(Hans-Gerd Claßen) #2

there’ll be tons of examples doing a forum search. :wink:


(Dave) #3

Perhaps you can point one out that is helpful? I’ve read a bunch and this seams to be you’re standard response on each. These forums are all that intuitive to search either.


(Hans-Gerd Claßen) #4
var request = new XMLHttpRequest();
request.open('GET', '/my/url/animation-text.json', true);

request.onload = function() {
  if (request.status >= 200 && request.status < 400) {

    var obj = JSON.parse(request.responseText);
var titleA = obj.mydata.block-a.title;
hypeDocument.getElementById('yourHypeElementsId').innerHTML = titleA;
  } else {


  }
};

request.onerror = function() {

};

request.send();

Scrolling Ticker Tape Help (loading text from JSON)
(Dave) #5

Thank you. That worked perfectly.