How do I load a JSON file into a dictionnary?

1 favourites
  • 6 posts
From the Asset Store
Source File, music and art pack for Android Negotiator
  • Hi !

    I tried to load a JSON file into a dictionary but my dictionary is still empty after the load.

    I didn't find any tutorial on this, I just used what I found in the documentation about AJAX and Dictionary but think I'm missing something :<

    Link to the project file.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • You can't load that JSON data into the dictionary directly. C3 dictionary requires a specific format of JSON string, it looks like this:

    {"c2dictionary":true,"data":{"A":"alpaca","B":"baboon","C":"cat"}}
    

    Your JSON string contains an array with several nested objects. A dictionary can't hold that data. I suggest you keep it in JSON object.

    If you want to convert it a dictionary, you'll need to parse it into JSON object (which you've already done), then loop through all entries and add them one by one to the dictionary.

    Check out the official template in C3:

    editor.construct.net

  • I finally found how to do it with the help of an helper on the Discord !

    The content of the JSON is the same than in the picture of the first post.

    Here is how :

    And the result :

    The tutorial part for the JSON is quite empty, you can do a lot with this plugin but it's really hard to understand by itself. I would love more tutorial about it.

  • With the result like that you don't really need the dictionary. You can access the same data from JSON.

    For example:

    JSON.Get("Skills.Double Strike.Mana")

    will return the same value as

    Dictionary.Get("Skills.Double Strike.Mana")

  • With the result like that you don't really need the dictionary. You can access the same data from JSON.

    For example:

    JSON.Get("Skills.Double Strike.Mana")

    will return the same value as

    Dictionary.Get("Skills.Double Strike.Mana")

    Hello. But would I be able to save the information directly from json to local storage? Or would I need to bake for a dictionary like he did?

  • Of course you can. Use JSON.ToCompactString expression.

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