Friday 20 September 2019

Reading from JSON File C#

Hey guys I have this json file (excerpt):
https://hastebin.com/uzifiteqol.json
I have created a discord bot which responds to commands and one of the commands is *card (card name)
This JSON file provides the stats of all the cards, but I want the user to access the lvl 9 stats based on the idname (card name he puts)
For example:
*card arrows
This should give the user the area damage of lvl 9 arrows that are shown in the json, but I am not sure how to access this stat. Heres what I have so far:


string jsonString = File.ReadAllText("/Users/me/Desktop/cardstatsfile.json");

This is where the json file location is on my computer (mac)
I am not sure how to go from there, I was thinking that I would need JToken.parse and parse through the file to look for the "idname" or the card specified by the user. Thanks in advance!


EDIT: Clarification: Because there are 75 cards, I want to obtain the values of elixircost, rarity, ect and also all the lvl 9 stats just by providing the idname. Or do I need to reformat the JSON to do this?

No comments:

Post a Comment

php - file_get_contents shows unexpected output while reading a file

I want to output an inline jpg image as a base64 encoded string, however when I do this : $contents = file_get_contents($filename); print &q...