How do I parse JSON Data in a loop?

0 favourites
  • 2 posts
From the Asset Store
Data+ is the best Data Management solution for Construct 3. It contains 4 Addons (Plugin & Behavior).
  • Hi. Does anyone have an example how I can use a loop on AJAX.LastData with JSON like below to get a list of all realm names and the realm data for each of the realms?

    example for a single realm:

    {"realms":[{"type":"rp","population":"medium","queue":false,"wintergrasp":{"area":1,"controlling-faction":1,"status":0,"next":1462710723768},"tol-barad":{"area":21,"controlling-faction":0,"status":1,"next":1462710700949},"status":true,"name":"Zirkel des Cenarius","slug":"zirkel-des-cenarius","battlegroup":"Embuscade / Hinterhalt","locale":"de_DE","timezone":"Europe/Paris","connected_realms":["zirkel-des-cenarius","todeswache"]}]}
    [/code:t1iilrg9]
    
    example for multiple realms:
    [code:t1iilrg9]{"realms":[{"type":"pvp","population":"high","queue":false,"wintergrasp":{"area":1,"controlling-faction":0,"status":0,"next":1462710732001},"tol-barad":{"area":21,"controlling-faction":0,"status":0,"next":1462712427270},"status":true,"name":"Aegwynn","slug":"aegwynn","battlegroup":"Misery","locale":"de_DE","timezone":"Europe/Paris","connected_realms":["aegwynn"]},{"type":"pve","population":"medium","queue":false,"wintergrasp":{"area":1,"controlling-faction":1,"status":0,"next":1462710724874},"tol-barad":{"area":21,"controlling-faction":1,"status":1,"next":1462710703055},"status":true,"name":"Aerie Peak","slug":"aerie-peak","battlegroup":"Reckoning / Abrechnung","locale":"en_GB","timezone":"Europe/Paris","connected_realms":["bronzebeard","aerie-peak"]},{"type":"pvp","population":"medium","queue":false,"wintergrasp":{"area":1,"controlling-faction":0,"status":0,"next":1462710910703},"tol-barad":{"area":21,"controlling-faction":0,"status":1,"next":1462710887883},"status":true,"name":"Agamaggan","slug":"agamaggan","battlegroup":"Reckoning / Abrechnung","locale":"en_GB","timezone":"Europe/Paris","connected_realms":["agamaggan","crushridge","bloodscalp","twilights-hammer","hakkar","emeriss"]}
    [/code:t1iilrg9]
    
    I tried  but I get an error when I try to load the AJAX data.
  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • you have error in example for multiple realms..you end with

    ]}[/code:2gfer4bq]
    should be
    [code:2gfer4bq]]}]}[/code:2gfer4bq]
    [code:2gfer4bq]{
      "realms": [
        {
          "type": "pvp",
          "population": "high",
          "queue": false,
          "wintergrasp": {
            "area": 1,
            "controlling-faction": 0,
            "status": 0,
            "next": 1462710732001
          },
          "tol-barad": {
            "area": 21,
            "controlling-faction": 0,
            "status": 0,
            "next": 1462712427270
          },
          "status": true,
          "name": "Aegwynn",
          "slug": "aegwynn",
          "battlegroup": "Misery",
          "locale": "de_DE",
          "timezone": "Europe/Paris",
          "connected_realms": [
            "aegwynn"
          ]
        },
        {
          "type": "pve",
          "population": "medium",
          "queue": false,
          "wintergrasp": {
            "area": 1,
            "controlling-faction": 1,
            "status": 0,
            "next": 1462710724874
          },
          "tol-barad": {
            "area": 21,
            "controlling-faction": 1,
            "status": 1,
            "next": 1462710703055
          },
          "status": true,
          "name": "Aerie Peak",
          "slug": "aerie-peak",
          "battlegroup": "Reckoning / Abrechnung",
          "locale": "en_GB",
          "timezone": "Europe/Paris",
          "connected_realms": [
            "bronzebeard",
            "aerie-peak"
          ]
        },
        {
          "type": "pvp",
          "population": "medium",
          "queue": false,
          "wintergrasp": {
            "area": 1,
            "controlling-faction": 0,
            "status": 0,
            "next": 1462710910703
          },
          "tol-barad": {
            "area": 21,
            "controlling-faction": 0,
            "status": 1,
            "next": 1462710887883
          },
          "status": true,
          "name": "Agamaggan",
          "slug": "agamaggan",
          "battlegroup": "Reckoning / Abrechnung",
          "locale": "en_GB",
          "timezone": "Europe/Paris",
          "connected_realms": [
            "agamaggan",
            "crushridge",
            "bloodscalp",
            "twilights-hammer",
            "hakkar",
            "emeriss"
          ]
        }
      ]
    }[/code:2gfer4bq]
    
    [url=https://app.box.com/s/ggx78mla8yrbai2jaxwf12j0887kksf0]realmsJSON.capx[/url]
    
    [b]Edit:[/b]
    
    [i]also..[/i]perhaps would be better to write json for multiple realms
    like this:
    [code:2gfer4bq]{
      "realm1": [
        {
          "type": "pvp",
          "population": "high",
          "queue": false,
          "wintergrasp": {
            "area": 1,
            "controlling-faction": 0,
            "status": 0,
            "next": 1462710732001
          },
          "tol-barad": {
            "area": 21,
            "controlling-faction": 0,
            "status": 0,
            "next": 1462712427270
          },
          "status": true,
          "name": "Aegwynn",
          "slug": "aegwynn",
          "battlegroup": "Misery",
          "locale": "de_DE",
          "timezone": "Europe/Paris",
          "connected_realms": [
            "aegwynn"
          ]
        }
      ],
      "realm2": [
        {
          "type": "pve",
          "population": "medium",
          "queue": false,
          "wintergrasp": {
            "area": 1,
            "controlling-faction": 1,
            "status": 0,
            "next": 1462710724874
          },
          "tol-barad": {
            "area": 21,
            "controlling-faction": 1,
            "status": 1,
            "next": 1462710703055
          },
          "status": true,
          "name": "Aerie Peak",
          "slug": "aerie-peak",
          "battlegroup": "Reckoning / Abrechnung",
          "locale": "en_GB",
          "timezone": "Europe/Paris",
          "connected_realms": [
            "bronzebeard",
            "aerie-peak"
          ]
        }
      ],
      "realm3": [
        {
          "type": "pvp",
          "population": "medium",
          "queue": false,
          "wintergrasp": {
            "area": 1,
            "controlling-faction": 0,
            "status": 0,
            "next": 1462710910703
          },
          "tol-barad": {
            "area": 21,
            "controlling-faction": 0,
            "status": 1,
            "next": 1462710887883
          },
          "status": true,
          "name": "Agamaggan",
          "slug": "agamaggan",
          "battlegroup": "Reckoning / Abrechnung",
          "locale": "en_GB",
          "timezone": "Europe/Paris",
          "connected_realms": [
            "agamaggan",
            "crushridge",
            "bloodscalp",
            "twilights-hammer",
            "hakkar",
            "emeriss"
          ]
        }
      ]
    }[/code:2gfer4bq]
    
    [url=https://app.box.com/s/a2veqt4yje338sc9ojoyxh4y2e8af1yu]realms2JSON.capx[/url]
Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)