Parsing JSON from web API

0 favourites
  • 7 posts
From the Asset Store
Create your quiz game! Create unlimited categories. Manage categories and questions
  • My name is Anderson Palma, I'm from OneDollarBoard project on indiegogo and we've created some python aplication to monitor our compain and notify our about new backers (it really keeps the team motivated)

    Everything is open source, so, everyone can use this too

    Indiegogo Backer Alert

    as expected, this is not a game, but an Application that monitor some web API that send it's data in a JSON

    E.g: website is ... funds.json [public id, no private token needed]

    the returned anwer is

    [quote:10vdpo4b]{'response': {'collected_funds': 9655,

    'contributions_count': 718,

    'funding_ends_at': '2016-07-10T23:59:59-07:00',

    'id': 1757572}}

    So we want to expand this projec from .py files to mobile web aplication, and think construct 2 is a grat tool for easy graphics and interface

    for this we need to parse JSON and get 'collected_funds' in a number variable

    can you help us?

    thanks for you time

  • You can fetch web-api data with AJAX object and then load it into Dictionary so you'll be able to grab any part from JSON easily. But to load it into a Dictionary you need a specific JSON format.

    Here's a snipped from my lib. It's PHP but I'm sure you get the point.

    So you have to change your web-api output or parse the fetched sting in C2 before loading into Dictionary. You can use regular expressions as well.

  • Well, in fact i don't even know how to use construct to open a website (dont mean showing it content in a frame, but to store it's data)

    All i need is to store 'collected_funds' in a numeric variable, I have no idea how to turn that .php code into construct....

    in python all i need is 3 lines:


    resp = urllib.request.urlopen(url).read()

    data = json.loads(resp.decode('utf-8'))

    funds = data['response']['collected_funds']

    can you help with some exemple?

  • Just checked it out quickly. Indiegogo does not allow cross-domain "grabs", so you can't fetch this data with AJAX. I'm afraid there is no other way in C2 to download remote data so you need to make a work-around.

    1. Create your own server side script which will download this JSON from Indiegogo (using CURL or whatever) once triggered and simply output it's content (kind of intermediary script).

    2. Set your server (or script) to allow AJAX fetch data from the different domain.

    To do that you can set Apache with .htaccess

    <IfModule mod_headers.c>
    Header set Access-Control-Allow-Origin "*"
    </IfModule> [/code:2s3jho53]
    3. Since you do the server script anyway, I would parse the JSON data already in that script and output only the number you want to fetch in C2.
    4. Now in C2 you just make a simple AJAX request as below:
  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • [plugin] JSON


    [quote:2uqrhri7] Indiegogo does not allow cross-domain "grabs"...

    works for me...(now??!)..

  • korbaach Thank you so much for the solution, I have been looking for it for days now. Thank you so much!

  • Complete novice, first post yet one of the things I wanted to be able to do is this. Cheers

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