[Solved] Network get and parse of json

I know I’ve missed something obvious, but after poring over the other json parsing threads i’m still lost.

The goal is to contact a server api, retrieve a json formatted list and parse the list into a structure I can call on. I thought I’d start simple and just try to process the “ID” field from the json and print it on screen.

This is the code I’m using (based on the “parse json on swapi” example).

with this as my get request:

My server is on a local network at If i paste that URL into a browser i get the following json list (the content of which is irrelevant, i just want to be able to parse a variable from it) :

{“ID”:“TR”,“Name”:“Test Room”,“Type”:“Standard”,“ScoreType”:“Time”,“Duration”:60,“Color”:"#000000",“Style”:{“Base”:“standard”,“BaseColor”:"#000000",“ClueIcon”:“images/clue.png”,“ClueUsedIcon”:“images/clue-used.png”,“Background”:"",“BackgroundLinkedToTimer”:true,“HideTimerWhenIdle”:false,“HideTimerWhenZero”:false,“Timer”:{“Font”:"",“FontBold”:false,“FontItalic”:false,“FontShadow”:false,“ForeColor”:"#ffffff",“Top”:0,“Left”:0,“Size”:480,“Override”:false,“Visible”:true},“Messages”:{“Font”:"",“FontBold”:false,“FontItalic”:false,“FontShadow”:false,“ForeColor”:"#ffffff",“Top”:0,“Left”:0,“Size”:40,“Override”:false,“Visible”:true},“Clues”:{“Top”:0,“Left”:0,“Override”:false,“Visible”:true},“Orientation”:1,“CustomCSS”:"",“CustomHTML”:""},“Clues”:{“Max”:3,“Bonus”:“None”,“BonusValue”:0,“Penalty”:“None”,“PenaltyValue”:0, “Duration”:20 },“MaxPlayers”:8,“DefaultTeamName”:“Investigators”,“State”:“Idle”,“Description”:"",“Marquee”:“stories/TR/m3-marquee.jpg”,“Poster”:“stories/TR/m3-poster.jpg”,“Chime”:{“Source”:“sound/chime.mp3”,“OnText”:true,“OnImage”:true,“OnAudio”:false,“OnVideo”:false},“Prologue”:false,“Epilogue”:false,“ExternalID”:"",“Rooms”:{},“Objectives”:{ },“Events”:{ },“RequiredScreens”:[],“ResetChecklist”:{ },“Music”:{},“Logs”:[{“Timestamp”:“04:18:24 pm”,“StoryID”:“TR”,“Type”:“Information”,“Message”:“Story is idle”}],“Values”:{ },“Languages”:[“English”,"","","",""],“Session”:{“Started”:“01/01/0001 00:00:00”,“Timer”:3600000,“TimerFactor”:1,“CluesRemaining”:0,“Score”:0,“Players”:0,“TeamName”:"",“Language”:0},“TimeBonus”:0,“AudioDucking”:false,“Active”:true }

If i run the above code, pressing the “a” key doesn’t seem to do anything.

However, if i change the get code to this:

(without the http://), then before i press anything, my debug shows my scene variables as image
and after i press “a”, they change to
and the text on screen changes to text = 0.

I wondered if there was a problem with talking to the local server, but i tried sending a server command from gdevelop and it worked fine.

(again, the function of the server here is moot, its just a testbed. I’m just trying to get consistent communications/before I proceed).

A number of posts identify getting 0 as an outcome when they incorrectly called the variable type. I don’t think I did that… but maybe? Any help on how to get gdev to isolate any of the json variables would be great. Thanks!

Oh good grief. I’m such a giant idiot. I somehow set the server to only reply to a specific port and the cache in my browser made it appear to still be serving. I fixed the port and the above code now works perfectly if anybody else is looking to parse json. Sorry!

So i was able to parse and read every variable in the json except ones with extra spaces. like: “Values”:{ “Variable1”: “test1”,“Variable2”: “test2” } Gdevelop cannot read Variable1 or 2. The only difference I can see is the space before the quotes on the variables and values. According to what I’ve been able to find, json shouldn’t care about the space, but it does seem to confuse gdevelop.

Well GDevelop uses the JS JSON parser so this is unlikely to be the problem. Nonetheless it is not good to have inconsistent JSON, it can lead to errors. Make also sure you use the same quotes everywhere (", ', ‘, ’, “, ”, and ` are different)