• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

DS_Map and twitch follower JSON file[Solved!]

L

Lavender

Guest
Greetings. I'll post the twitch json(the part I'm having trouble with) then explain
Code:
{
   "follows": [{
     "created_at": "2016-12-14T00:32:22.963907Z",
     "notifications": false,
     "user": {
           "_id": "129454141",
     }
   },
   ...
   ]
}
What I want from this is to grab the value of "_id" but its nested weirdly inside the follows. I've tried upsteping into follows as a map but all I get is a 1(its value) followed by everything else being undefined. I've been searching all day for anything to help with no luck. Hopping someone on the forums may know/solves how to get this, thanks!
 

YellowAfterlife

ᴏɴʟɪɴᴇ ᴍᴜʟᴛɪᴘʟᴀʏᴇʀ
Forum Staff
Moderator
You would gradually unpack and loop over the structure,
Code:
var data = json_decode(<that JSON string>);
var follows_list = data[?"follows"];
var follows_size = ds_list_size(follows_list);
for (var i = 0; i < follows_size; i += 1) {
    var follows_item = follows_list[|i];
    var follows_user = follows_item[?"user"];
    var follows_user_id = follows_user[?"_id"];
    show_debug_message(follows_user_id);
}
ds_map_destroy(data);
 

Tsa05

Member
You have a map containing a list containing a map containing a map containing a key.

myMap = json_decode("that stuff");

followList = myMap[? "follows"]; // This is the ds_list associated with "follows"

firstFollower = followList[| 0]; // This is the first map in the list

userMap = firstFollower[? "user"]; // This is the "user" map inside

userID = userMap[? "_id"];
 
Top