mishappp commented on a Page, JSON for MIRC  -  Jan 16, 2015

How would I access an array formatted like this? http://pastebin.com/8tSnU5WV

When I try to use

echo -a $json(gameinfo,game,teamTwo,array,2)

I get a random string of numbers. I'm sure I'm just doing it wrong but I don't quite know how to do it. I saw the examples, but I'm not sure how to apply it to URL get. I'm a newbie be gentle. I'm posting this again, because I accidentally posted it as a reply.

SReject  -  Jan 16, 2015

There is no "teamTwo" in the pastebin you posted. Instead of showing just a snippet of the problematic code, could you pastebin the whole code?

mishappp  -  Jan 16, 2015

Yeah, sorry about that, as for the code this is pretty much it all I have is a jsonopen -ud to the API, I can get some information but none of the nested information hence why I'm sure I'm probably doing this wrong.

http://pastebin.com/9H43Gbav

SReject  -  Jan 16, 2015

When accessing the json, if you are trying to access a 'node' that has child members, a reference to those child members is returned, instead of a value. To get values from the json as you listed, you'd have to specify each member you want to grab.

This returns a reference to game.teamTwo.array[0]:

alias test_json {
    jsonopen -ud test http://pastebin.com/raw.php?i=9H43Gbav
    echo -s Rating: $json(test, game, teamTwo, array, 0)
}

This gets teamRating and pickMode from game.teamTwo.array[0]:

alias test_json {
    jsonopen -ud test http://pastebin.com/raw.php?i=9H43Gbav
    echo -s Rating: $json(test, game, teamTwo, array, 0, teamRating)
    echo -s pickMode: $json(test, game, teamTwo, array, 1, pickMode)
}
mishappp  -  Jan 16, 2015

Works great. Thank you.

Sign in to comment

Are you sure you want to unfollow this person?
Are you sure you want to delete this?
Click "Unsubscribe" to stop receiving notices pertaining to this post.
Click "Subscribe" to resume notices pertaining to this post.