How do I check if an id of an assets exists? (JSON - loop)

0 favourites
  • 6 posts
From the Asset Store
For Adventure, Action, Heroes, Sci-fi and Action-RPG games.
  • Hello there,

    I have a question regarding the manipulation of a JSON. I took the example from this topic: https://www.construct.net/en/forum/construct-3/scripting-51/parse-json-objects-return-149689

    Here the example I'm working on it, I did several tests but I can't make it work as I want: https://umbriadesign.it/json-test.c3p

    Basically, I need to check if the following json contains a specific id item from a string list. If the json file contains it, then I need to retrieve the name or other parameters of the following id item, if not, just mark as not found.

    I'm working on it. If I make it work I will share it here. Help is appreciate.

    Thank you

    Tagged:

  • First of all, you need to move event #2 to be a sub-event under #1.

    Remove quotation marks in the nftList variable.

    And check the structure of your JSON file - there is no "raids" array in it.

  • dop2000 Thank you for the reply. I always have problems with manipulating arrays. From the original example which works, the JSON structure looks a little bit different from the nftUser.json.

    The raids is set on the Json, which contains the array taken from the the nftUser.json file. So, I guessed that should be set as it was.

    I tried your suggestions, but I can't make it work. I would be happy if someone could show how the events should be. I will keep trying. Thank you

  • In your function you are trying to get data from "raids" array in JSON. But your JSON data doesn't have an array with this name. There is "assets" array, maybe that's what you meant?

    You can use any online JSON formatting tool to check the structure of your JSON file.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • dop2000 Hello, thank you for the reply.

    The json looks like this and is vaid (checked on jsonformatter): https://umbriadesign.it/nftJson.json

    You can see the raids is being used. I'm trying to understand how I can access the id (the one above token_id) and get the data I want (name = "CryptoPunk #721", traits....etc).

    I'm not good with json manipulation. From my list (the nftList string) I would like to see if there is one in the json, and if there is, get the specific value for that specific item id.

    Thanks again

  • Yeah, but if you open the file nftUser.json included in your project, there is no "raids" array. You need to either copy the correct data into the project file, or request it from the web server.

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