Json string help!

0 favourites
  • 6 posts
From the Asset Store
Game with complete Source-Code (Construct 3 / .c3p) + HTML5 Exported.
  • Hi guys I have a url that gets data in a json format and shows it in a string like this:

    [{"id":"1","points":"3"},{"id":"2","points":"95"}]

    How do I get c3 to request the url and get this infomation in an array or just a textbox?

  • I can only point you to my help thread which no one answered either.

    Maybe you can find a hint in there, you can either change your json to a contruct formed one or hope for someone to answer :) really curious myself how to get a normal json in C3

    construct.net/forum/construct-3/how-do-i-8/json-to-dictionary-135343

  • GarryPlays Thanks Yeah same im desperate for c2 to be able to do this! Message me if you get anything! I personally emailed Ashley to see if he had an answer nothing yet! Ill let you know when he replies!

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • You use a the ajax object to request the url to get the string.

    There may be a json plugin that lets you parse the text, but you can also just do it with javascipt via the browser object.

    Basically you'd do something like:

    Start of layout

    --- ajax: request url "www.myurl.com/data/"

    on ajax complete

    --- browser: execute js "window.data=" & ajax.returnData

    --- text: set text to browser.execjs("data[0].points")

    Or at least very similar. I didn't bother to check if that's the correct names of stuff.

    It uses window.data to make data a global js variable. This doesn't work in all exports.

    So then in js you can access the global "data" variable to get at your values. Maybe a basic js tutorial could shed some light on this. Typos or errors would spit something to the browser console.

    That json is an array of two dictionaries, so you could start with the above and create some events to create two dictionaries and populate them i suppose.

  • R0J0hound Hi I have tried this but I still get nothing I dont know why please help :(

  • There are a fair amount of places where it can't work so I'd recommend testing every step of the way to verify it's working.

    Like when you do the ajax request, verify it works by setting some text in the "on complete" event. If it doesn't, then maybe look at the manual portion of ajax for ways to see what the error is. Maybe a bad request or something.

    If that works then you could set the text to the returned text to see if it indeed is the data you wanted.

    Next you can do the action to set the "data" variable. Open the browser console. Are there any errors? With the console open type "data" in the prompt. It should show a collapsible tree of the json.

    So the same for any other js you run with the browser object.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)