How to search for keys in Json files?

0 favourites
  • 7 posts
From the Asset Store
Searching
$16 USD
Searching is a game where you are challenged to find all the images with the requested letter in 30 seconds.
  • I have a Json file that was created within construct 3 with the dictionary's native plugin in the "files" folder. It's like a dictionary, but I know that those files created in the file folder are actually Json files, correct?

    What I want to do is the following:

    Start of layout / Request file.json('tag")

    Ajax on "tag" completed / Parse json string Ajax.lastData

    So far so good. I uploaded the Json file.

    All the keys in my Json file are numbers. But what I want to do is parse all the keys looking for a specific number, until I find that number.

    When it finds the key that matches the number I want, I want it to return the value of that key. And then I want to show that value in a text object. How could I do this? I'm breaking my head because I'm a beginner at this.

    Tagged:

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Generally speaking, you do a JSON for each, along with a system compare two values, json.currentvalue = value.

    Depends on the format of your JSON though, if you can loop through objects at a path.

    Considering you saved the json with the dictionary object though, it would make more sense to load the json back into the dictionary object, and use the dictionary.get(key) expression.

    Seems kinda silly to use the dictionary object to save as json to try to parse it as json and manually recreate the functionality of the dictionary object.

  • I used the json dictionary object because it's easier to edit so many keys manually. And it is also possible to retrieve key values directly from json, without having to pass to a dictionary. But I can retrieve values in that json, but I can't parse the whole json looking for the numeric key I want.

  • Yes, you can still save the dictionary as a JSON, edit it as text, and then load it back into a dictionary.

    You can get to the key either way, it's just easier if you use the dictionary object.

    Do you have a sample json available? I can make an example to get to the value both ways, and you can see the difference.

  • Here's my imaginary Json I made for this example here, which is nothing more than these keys and values in the construct's own visual dictionary editor. All the keys are numbers (the keycodes) and the values are the keys.

    What I wanted was that when the player pressed any key, the corresponding key appeared in a sprite font. In fact, I already managed to do this yesterday without a variable, without a dictionary or json, just with: Keyboard.StringFromKeyCode(Keyboard.LastKeyCode)

    I didn't know that there was this expression in the keyboard object called StringFromKeyCode, I only knew the LastKeyCode, that's why I tried to do it like this. But let's assume that I had to do this by json, would you know how to look for the keycode corresponding to the last key pressed by the keyboard in that json and return the value of that key?

    {

    "c2dictionary": true,

    "data": {

    "9": "TAB",

    "13": "ENTER",

    "17": "CTRL",

    "18": "ALT",

    "32": "SPACE",

    "37": "LEFT",

    "38": "FORWARD",

    "39": "RIGHT",

    "40": "BACKWARD",

    "41": "\\",

    "45": "-",

    "48": 0,

    "49": 1,

    "50": 2,

    "51": 3,

    "52": 4,

    "53": 5,

    "54": 6,

    "55": 7,

    "56": 8,

    "57": 9,

    "61": "=",

    "65": "A",

    "66": "B",

    "67": "C",

    "68": "D",

    "69": "E",

    "70": "F",

    "71": "G",

    "72": "H",

    "73": "I",

    "74": "J",

    "75": "K",

    "76": "L",

    "77": "M",

    "78": "N",

    "79": "O",

    "80": "P",

    "81": "Q",

    "82": "R",

    "83": "S",

    "84": "T",

    "85": "U",

    "86": "V",

    "87": "W",

    "88": "X",

    "89": "Y",

    "90": "Z",

    "91": "[", "93": "]",

    "97": 1,

    "98": 2,

    "99": 3,

    "100": 4,

    "101": 5,

    "102": 6,

    "103": 7,

    "104": 8,

    "105": 9,

    "106": "*",

    "107": "+",

    "108": "L",

    "109": "-",

    "110": ",",

    "111": "/",

    "180": "´",

    "188": ",",

    "190": ".",

    "191": ";",

    "192": "'",

    "193": "/",

    "194": ".",

    "199": "Ç",

    "222": "~",

    "231": "Ç"

    }

    }

  • dropbox.com/s/x4o7yl383x3tyvo/dictionaryjsonexample.c3p

    Yeah if you want to just display the actual key for the key code no need for a dictionary/json. But if you want to remap keys, this is when it would be useful.

  • You were amazing. It's hard to believe, you gave me both examples, I saw the code, well summarized, very clear. This will help me a lot, I didn't know the expression "SRT", although it's in the documentation, there's always something there to see. It's the kind of thing I'm going to study for a few days, practicing different examples of this to better memorize. I thank you very much for donating your time to this. Thank you very much, God bless you.

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