// Json Template
/*
{
"id": 1,
"name": {
"english": "Bulbasaur",
"japanese": "フシギダネ",
"chinese": "妙蛙种子",
"french": "Bulbizarre"},
"type": [
"Grass",
"Poison"],
"stats": {
"HP": 45,
"Attack": 49,
"Defense": 49,
"Sp. Attack": 65,
"Sp. Defense": 65,
"Speed": 45}
}
*/
//Libraries
using Newtonsoft.Json;
//1. Get the file from the path and read it!
string path = @"C:\Users\c e r e s\Desktop\Pokemon\pokedex.json";
string jsonFile = File.ReadAllText(path);
//2. Access Pokemon Class and deserialize:
Pokemon pkmn = JsonConvert.DeserializeObject<Pokemon>(jsonFile);
//3. Iterate values from the array
Console.WriteLine(pkmn.id);
Console.ReadLine();
//Storage structure
public class Pokemon {
public int id { get; set; }
public Dictionary<string, int> name { get; set; }
public string[] type { get; set; }
public Dictionary<string, int> stats { get; set; }
};
// Json Template
/*
{
"id": 1,
"name": {
"english": "Bulbasaur",
"japanese": "フシギダネ",
"chinese": "妙蛙种子",
"french": "Bulbizarre"},
"type": [
"Grass",
"Poison"],
"stats": {
"HP": 45,
"Attack": 49,
"Defense": 49,
"Sp. Attack": 65,
"Sp. Defense": 65,
"Speed": 45}
}
*/
//Libraries
using Newtonsoft.Json;
//1. Get the file from the path and read it!
string path = @"C:\Users\c e r e s\Desktop\Pokemon\pokedex.json";
string jsonFile = File.ReadAllText(path);
//2. Access Pokemon Class and deserialize:
Pokemon pkmn = JsonConvert.DeserializeObject<Pokemon>(jsonFile);
//3. Iterate values from the array
Console.WriteLine(pkmn.id);
Console.ReadLine();
//Storage structure
public class Pokemon {
public int id { get; set; }
public Dictionary<string, int> name { get; set; }
public string[] type { get; set; }
public Dictionary<string, int> stats { get; set; }
};