0

Hola amigos quiero deseralizar un json de un api de pokemon https://pokeapi.co/api/v2/pokemon/ditto , pero tengo problemas utilice esta herramienta para convertir ese json en un clase modelo con https://www.jsonutils.com/ , le hice algunos ajustes por que note que creaba muy bien la clase, pero aun cuando le ponga la conversion original mi error a hacer

var respContent = await respPokeApi.Content.ReadAsStringAsync();
  var json_d = JsonConvert.DeserializeObject<List<PokemonDetail>>(respContent);

siempre es

Newtonsoft.Json.JsonSerializationException: 'Cannot deserialize the current JSON object (e.g. {"name":"value"}) into type 'System.Collections.Generic.List`1[Pokedex.Core.Models.PokemonDetail]' because the type requires a JSON array (e.g. [1,2,3]) to deserialize correctly.

To fix this error either change the JSON to a JSON array (e.g. [1,2,3]) or change the deserialized type so that it is a normal .NET type (e.g. not a primitive type like integer, not a collection type like an array or List) that can be deserialized from a JSON object. JsonObjectAttribute can also be added to the type to force it to deserialize from a JSON object. Path 'abilities', line 1, position 13.'

es error por deseralizar

Esta es la respuesta de la poke api

{
"abilities": [
    {
        "ability": {
            "name": "imposter",
            "url": "https://pokeapi.co/api/v2/ability/150/"
        },
        "is_hidden": true,
        "slot": 3
    },
    {
        "ability": {
            "name": "limber",
            "url": "https://pokeapi.co/api/v2/ability/7/"
        },
        "is_hidden": false,
        "slot": 1
    }
],
"base_experience": 101,
"forms": [
    {
        "name": "ditto",
        "url": "https://pokeapi.co/api/v2/pokemon-form/132/"
    }
],
"game_indices": [
    {
        "game_index": 132,
        "version": {
            "name": "white-2",
            "url": "https://pokeapi.co/api/v2/version/22/"
        }
    },
    {
        "game_index": 132,
        "version": {
            "name": "black-2",
            "url": "https://pokeapi.co/api/v2/version/21/"
        }
    },
    {
        "game_index": 132,
        "version": {
            "name": "white",
            "url": "https://pokeapi.co/api/v2/version/18/"
        }
    },
    {
        "game_index": 132,
        "version": {
            "name": "black",
            "url": "https://pokeapi.co/api/v2/version/17/"
        }
    },
    {
        "game_index": 132,
        "version": {
            "name": "soulsilver",
            "url": "https://pokeapi.co/api/v2/version/16/"
        }
    },
    {
        "game_index": 132,
        "version": {
            "name": "heartgold",
            "url": "https://pokeapi.co/api/v2/version/15/"
        }
    },
    {
        "game_index": 132,
        "version": {
            "name": "platinum",
            "url": "https://pokeapi.co/api/v2/version/14/"
        }
    },
    {
        "game_index": 132,
        "version": {
            "name": "pearl",
            "url": "https://pokeapi.co/api/v2/version/13/"
        }
    },
    {
        "game_index": 132,
        "version": {
            "name": "diamond",
            "url": "https://pokeapi.co/api/v2/version/12/"
        }
    },
    {
        "game_index": 132,
        "version": {
            "name": "leafgreen",
            "url": "https://pokeapi.co/api/v2/version/11/"
        }
    },
    {
        "game_index": 132,
        "version": {
            "name": "firered",
            "url": "https://pokeapi.co/api/v2/version/10/"
        }
    },
    {
        "game_index": 132,
        "version": {
            "name": "emerald",
            "url": "https://pokeapi.co/api/v2/version/9/"
        }
    },
    {
        "game_index": 132,
        "version": {
            "name": "sapphire",
            "url": "https://pokeapi.co/api/v2/version/8/"
        }
    },
    {
        "game_index": 132,
        "version": {
            "name": "ruby",
            "url": "https://pokeapi.co/api/v2/version/7/"
        }
    },
    {
        "game_index": 132,
        "version": {
            "name": "crystal",
            "url": "https://pokeapi.co/api/v2/version/6/"
        }
    },
    {
        "game_index": 132,
        "version": {
            "name": "silver",
            "url": "https://pokeapi.co/api/v2/version/5/"
        }
    },
    {
        "game_index": 132,
        "version": {
            "name": "gold",
            "url": "https://pokeapi.co/api/v2/version/4/"
        }
    },
    {
        "game_index": 76,
        "version": {
            "name": "yellow",
            "url": "https://pokeapi.co/api/v2/version/3/"
        }
    },
    {
        "game_index": 76,
        "version": {
            "name": "blue",
            "url": "https://pokeapi.co/api/v2/version/2/"
        }
    },
    {
        "game_index": 76,
        "version": {
            "name": "red",
            "url": "https://pokeapi.co/api/v2/version/1/"
        }
    }
],
"height": 3,
"held_items": [
    {
        "item": {
            "name": "metal-powder",
            "url": "https://pokeapi.co/api/v2/item/234/"
        },
        "version_details": [
            {
                "rarity": 5,
                "version": {
                    "name": "ultra-sun",
                    "url": "https://pokeapi.co/api/v2/version/29/"
                }
            },
            {
                "rarity": 5,
                "version": {
                    "name": "moon",
                    "url": "https://pokeapi.co/api/v2/version/28/"
                }
            },
            {
                "rarity": 5,
                "version": {
                    "name": "y",
                    "url": "https://pokeapi.co/api/v2/version/24/"
                }
            },
            {
                "rarity": 5,
                "version": {
                    "name": "x",
                    "url": "https://pokeapi.co/api/v2/version/23/"
                }
            },
            {
                "rarity": 5,
                "version": {
                    "name": "white-2",
                    "url": "https://pokeapi.co/api/v2/version/22/"
                }
            },
            {
                "rarity": 5,
                "version": {
                    "name": "black-2",
                    "url": "https://pokeapi.co/api/v2/version/21/"
                }
            },
            {
                "rarity": 5,
                "version": {
                    "name": "white",
                    "url": "https://pokeapi.co/api/v2/version/18/"
                }
            },
            {
                "rarity": 5,
                "version": {
                    "name": "black",
                    "url": "https://pokeapi.co/api/v2/version/17/"
                }
            },
            {
                "rarity": 5,
                "version": {
                    "name": "soulsilver",
                    "url": "https://pokeapi.co/api/v2/version/16/"
                }
            },
            {
                "rarity": 5,
                "version": {
                    "name": "heartgold",
                    "url": "https://pokeapi.co/api/v2/version/15/"
                }
            },
            {
                "rarity": 5,
                "version": {
                    "name": "platinum",
                    "url": "https://pokeapi.co/api/v2/version/14/"
                }
            },
            {
                "rarity": 5,
                "version": {
                    "name": "pearl",
                    "url": "https://pokeapi.co/api/v2/version/13/"
                }
            },
            {
                "rarity": 5,
                "version": {
                    "name": "diamond",
                    "url": "https://pokeapi.co/api/v2/version/12/"
                }
            },
            {
                "rarity": 5,
                "version": {
                    "name": "leafgreen",
                    "url": "https://pokeapi.co/api/v2/version/11/"
                }
            },
            {
                "rarity": 5,
                "version": {
                    "name": "firered",
                    "url": "https://pokeapi.co/api/v2/version/10/"
                }
            },
            {
                "rarity": 5,
                "version": {
                    "name": "emerald",
                    "url": "https://pokeapi.co/api/v2/version/9/"
                }
            },
            {
                "rarity": 5,
                "version": {
                    "name": "sapphire",
                    "url": "https://pokeapi.co/api/v2/version/8/"
                }
            },
            {
                "rarity": 5,
                "version": {
                    "name": "ruby",
                    "url": "https://pokeapi.co/api/v2/version/7/"
                }
            }
        ]
    },
    {
        "item": {
            "name": "quick-powder",
            "url": "https://pokeapi.co/api/v2/item/251/"
        },
        "version_details": [
            {
                "rarity": 50,
                "version": {
                    "name": "ultra-sun",
                    "url": "https://pokeapi.co/api/v2/version/29/"
                }
            },
            {
                "rarity": 50,
                "version": {
                    "name": "moon",
                    "url": "https://pokeapi.co/api/v2/version/28/"
                }
            },
            {
                "rarity": 50,
                "version": {
                    "name": "y",
                    "url": "https://pokeapi.co/api/v2/version/24/"
                }
            },
            {
                "rarity": 50,
                "version": {
                    "name": "x",
                    "url": "https://pokeapi.co/api/v2/version/23/"
                }
            },
            {
                "rarity": 50,
                "version": {
                    "name": "white-2",
                    "url": "https://pokeapi.co/api/v2/version/22/"
                }
            },
            {
                "rarity": 50,
                "version": {
                    "name": "black-2",
                    "url": "https://pokeapi.co/api/v2/version/21/"
                }
            },
            {
                "rarity": 50,
                "version": {
                    "name": "white",
                    "url": "https://pokeapi.co/api/v2/version/18/"
                }
            },
            {
                "rarity": 50,
                "version": {
                    "name": "black",
                    "url": "https://pokeapi.co/api/v2/version/17/"
                }
            },
            {
                "rarity": 50,
                "version": {
                    "name": "soulsilver",
                    "url": "https://pokeapi.co/api/v2/version/16/"
                }
            },
            {
                "rarity": 50,
                "version": {
                    "name": "heartgold",
                    "url": "https://pokeapi.co/api/v2/version/15/"
                }
            },
            {
                "rarity": 50,
                "version": {
                    "name": "platinum",
                    "url": "https://pokeapi.co/api/v2/version/14/"
                }
            },
            {
                "rarity": 50,
                "version": {
                    "name": "pearl",
                    "url": "https://pokeapi.co/api/v2/version/13/"
                }
            },
            {
                "rarity": 50,
                "version": {
                    "name": "diamond",
                    "url": "https://pokeapi.co/api/v2/version/12/"
                }
            }
        ]
    }
],
"id": 132,
"is_default": true,
"location_area_encounters": "https://pokeapi.co/api/v2/pokemon/132/encounters",
"moves": [
    {
        "move": {
            "name": "transform",
            "url": "https://pokeapi.co/api/v2/move/144/"
        },
        "version_group_details": [
            {
                "level_learned_at": 1,
                "move_learn_method": {
                    "name": "level-up",
                    "url": "https://pokeapi.co/api/v2/move-learn-method/1/"
                },
                "version_group": {
                    "name": "ultra-sun-ultra-moon",
                    "url": "https://pokeapi.co/api/v2/version-group/18/"
                }
            },
            {
                "level_learned_at": 1,
                "move_learn_method": {
                    "name": "level-up",
                    "url": "https://pokeapi.co/api/v2/move-learn-method/1/"
                },
                "version_group": {
                    "name": "sun-moon",
                    "url": "https://pokeapi.co/api/v2/version-group/17/"
                }
            },
            {
                "level_learned_at": 1,
                "move_learn_method": {
                    "name": "level-up",
                    "url": "https://pokeapi.co/api/v2/move-learn-method/1/"
                },
                "version_group": {
                    "name": "omega-ruby-alpha-sapphire",
                    "url": "https://pokeapi.co/api/v2/version-group/16/"
                }
            },
            {
                "level_learned_at": 1,
                "move_learn_method": {
                    "name": "level-up",
                    "url": "https://pokeapi.co/api/v2/move-learn-method/1/"
                },
                "version_group": {
                    "name": "x-y",
                    "url": "https://pokeapi.co/api/v2/version-group/15/"
                }
            },
            {
                "level_learned_at": 1,
                "move_learn_method": {
                    "name": "level-up",
                    "url": "https://pokeapi.co/api/v2/move-learn-method/1/"
                },
                "version_group": {
                    "name": "black-2-white-2",
                    "url": "https://pokeapi.co/api/v2/version-group/14/"
                }
            },
            {
                "level_learned_at": 1,
                "move_learn_method": {
                    "name": "level-up",
                    "url": "https://pokeapi.co/api/v2/move-learn-method/1/"
                },
                "version_group": {
                    "name": "xd",
                    "url": "https://pokeapi.co/api/v2/version-group/13/"
                }
            },
            {
                "level_learned_at": 1,
                "move_learn_method": {
                    "name": "level-up",
                    "url": "https://pokeapi.co/api/v2/move-learn-method/1/"
                },
                "version_group": {
                    "name": "colosseum",
                    "url": "https://pokeapi.co/api/v2/version-group/12/"
                }
            },
            {
                "level_learned_at": 1,
                "move_learn_method": {
                    "name": "level-up",
                    "url": "https://pokeapi.co/api/v2/move-learn-method/1/"
                },
                "version_group": {
                    "name": "black-white",
                    "url": "https://pokeapi.co/api/v2/version-group/11/"
                }
            },
            {
                "level_learned_at": 1,
                "move_learn_method": {
                    "name": "level-up",
                    "url": "https://pokeapi.co/api/v2/move-learn-method/1/"
                },
                "version_group": {
                    "name": "heartgold-soulsilver",
                    "url": "https://pokeapi.co/api/v2/version-group/10/"
                }
            },
            {
                "level_learned_at": 1,
                "move_learn_method": {
                    "name": "level-up",
                    "url": "https://pokeapi.co/api/v2/move-learn-method/1/"
                },
                "version_group": {
                    "name": "platinum",
                    "url": "https://pokeapi.co/api/v2/version-group/9/"
                }
            },
            {
                "level_learned_at": 1,
                "move_learn_method": {
                    "name": "level-up",
                    "url": "https://pokeapi.co/api/v2/move-learn-method/1/"
                },
                "version_group": {
                    "name": "diamond-pearl",
                    "url": "https://pokeapi.co/api/v2/version-group/8/"
                }
            },
            {
                "level_learned_at": 1,
                "move_learn_method": {
                    "name": "level-up",
                    "url": "https://pokeapi.co/api/v2/move-learn-method/1/"
                },
                "version_group": {
                    "name": "firered-leafgreen",
                    "url": "https://pokeapi.co/api/v2/version-group/7/"
                }
            },
            {
                "level_learned_at": 1,
                "move_learn_method": {
                    "name": "level-up",
                    "url": "https://pokeapi.co/api/v2/move-learn-method/1/"
                },
                "version_group": {
                    "name": "emerald",
                    "url": "https://pokeapi.co/api/v2/version-group/6/"
                }
            },
            {
                "level_learned_at": 1,
                "move_learn_method": {
                    "name": "level-up",
                    "url": "https://pokeapi.co/api/v2/move-learn-method/1/"
                },
                "version_group": {
                    "name": "ruby-sapphire",
                    "url": "https://pokeapi.co/api/v2/version-group/5/"
                }
            },
            {
                "level_learned_at": 1,
                "move_learn_method": {
                    "name": "level-up",
                    "url": "https://pokeapi.co/api/v2/move-learn-method/1/"
                },
                "version_group": {
                    "name": "crystal",
                    "url": "https://pokeapi.co/api/v2/version-group/4/"
                }
            },
            {
                "level_learned_at": 1,
                "move_learn_method": {
                    "name": "level-up",
                    "url": "https://pokeapi.co/api/v2/move-learn-method/1/"
                },
                "version_group": {
                    "name": "gold-silver",
                    "url": "https://pokeapi.co/api/v2/version-group/3/"
                }
            },
            {
                "level_learned_at": 1,
                "move_learn_method": {
                    "name": "level-up",
                    "url": "https://pokeapi.co/api/v2/move-learn-method/1/"
                },
                "version_group": {
                    "name": "yellow",
                    "url": "https://pokeapi.co/api/v2/version-group/2/"
                }
            },
            {
                "level_learned_at": 1,
                "move_learn_method": {
                    "name": "level-up",
                    "url": "https://pokeapi.co/api/v2/move-learn-method/1/"
                },
                "version_group": {
                    "name": "red-blue",
                    "url": "https://pokeapi.co/api/v2/version-group/1/"
                }
            }
        ]
    }
],
"name": "ditto",
"order": 197,
"species": {
    "name": "ditto",
    "url": "https://pokeapi.co/api/v2/pokemon-species/132/"
},
"sprites": {
    "back_default": "https://raw.githubusercontent.com/PokeAPI/sprites/master/sprites/pokemon/back/132.png",
    "back_female": null,
    "back_shiny": "https://raw.githubusercontent.com/PokeAPI/sprites/master/sprites/pokemon/back/shiny/132.png",
    "back_shiny_female": null,
    "front_default": "https://raw.githubusercontent.com/PokeAPI/sprites/master/sprites/pokemon/132.png",
    "front_female": null,
    "front_shiny": "https://raw.githubusercontent.com/PokeAPI/sprites/master/sprites/pokemon/shiny/132.png",
    "front_shiny_female": null
},
"stats": [
    {
        "base_stat": 48,
        "effort": 0,
        "stat": {
            "name": "speed",
            "url": "https://pokeapi.co/api/v2/stat/6/"
        }
    },
    {
        "base_stat": 48,
        "effort": 0,
        "stat": {
            "name": "special-defense",
            "url": "https://pokeapi.co/api/v2/stat/5/"
        }
    },
    {
        "base_stat": 48,
        "effort": 0,
        "stat": {
            "name": "special-attack",
            "url": "https://pokeapi.co/api/v2/stat/4/"
        }
    },
    {
        "base_stat": 48,
        "effort": 0,
        "stat": {
            "name": "defense",
            "url": "https://pokeapi.co/api/v2/stat/3/"
        }
    },
    {
        "base_stat": 48,
        "effort": 0,
        "stat": {
            "name": "attack",
            "url": "https://pokeapi.co/api/v2/stat/2/"
        }
    },
    {
        "base_stat": 48,
        "effort": 1,
        "stat": {
            "name": "hp",
            "url": "https://pokeapi.co/api/v2/stat/1/"
        }
    }
],
"types": [
    {
        "slot": 1,
        "type": {
            "name": "normal",
            "url": "https://pokeapi.co/api/v2/type/1/"
        }
    }
],
"weight": 40

}

Este es mi modelo

namespace Pokedex.Core.Models

{

public class ability
{
    public string Name { get; set; }
    public string Url { get; set; }
}

public class abilities
{
    public ability Ability { get; set; }
    public bool IsHidden { get; set; }
    public int Slot { get; set; }
}

public class Form
{
    public string Name { get; set; }
    public string Url { get; set; }
}

public class Version
{
    public string Name { get; set; }
    public string Url { get; set; }
}

public class GameIndice
{
    public int GameIndex { get; set; }
    public Version Version { get; set; }
}

public class Move
{
    public string Name { get; set; }
    public string Url { get; set; }
}

public class MoveLearnMethod
{
    public string Name { get; set; }
    public string Url { get; set; }
}

public class VersionGroup
{
    public string Name { get; set; }
    public string Url { get; set; }
}

public class VersionGroupDetail
{
    public int LevelLearnedAt { get; set; }
    public MoveLearnMethod MoveLearnMethod { get; set; }
    public VersionGroup VersionGroup { get; set; }
}

public class Moves
{
    public Move Move { get; set; }
    public IList<VersionGroupDetail> VersionGroupDetails { get; set; }
}

public class Species
{
    public string Name { get; set; }
    public string Url { get; set; }
}

public class Sprites
{
    public string BackDefault { get; set; }
    public object BackFemale { get; set; }
    public string BackShiny { get; set; }
    public object BackShinyFemale { get; set; }
    public string FrontDefault { get; set; }
    public object FrontFemale { get; set; }
    public string FrontShiny { get; set; }
    public object FrontShinyFemale { get; set; }
}

public class Stat
{
    public string Name { get; set; }
    public string Url { get; set; }
}

public class Stats
{
    public int BaseStat { get; set; }
    public int Effort { get; set; }
    public Stat Stat { get; set; }
}

public class Type
{
    public string Name { get; set; }
    public string Url { get; set; }
}

public class Types
{
    public int Slot { get; set; }
    public Type Type { get; set; }
}

public class PokemonDetail
{
    public IList<abilities> Abilities { get; set; }
    public int BaseExperience { get; set; }
    public IList<Form> Forms { get; set; }
    public IList<GameIndice> GameIndices { get; set; }
    public int Height { get; set; }
    public IList<object> HeldItems { get; set; }
    public int Id { get; set; }
    public bool IsDefault { get; set; }
    public string LocationAreaEncounters { get; set; }
    public IList<Move> Moves { get; set; }
    public string Name { get; set; }
    public int Order { get; set; }
    public Species Species { get; set; }
    public Sprites Sprites { get; set; }
    public IList<Stat> Stats { get; set; }
    public IList<Type> Types { get; set; }
    public int Weight { get; set; }
}

}

y ya por ultimo aqui donde lo ejecuto

        public async Task<IList<PokemonDetail>> GetPokemonDetail(string u)
    {
        var uri = u;
        HttpClient client = new HttpClient();
        var respPokeApi = await client.GetAsync(uri);
        var pokemondetail = new List<PokemonDetail>();

        if (respPokeApi.IsSuccessStatusCode)
        {
            var respContent = await respPokeApi.Content.ReadAsStringAsync();
            var json_d = JsonConvert.DeserializeObject<List<PokemonDetail>>(respContent);

            pokemondetail = json_d;
        }

        return pokemondetail;
    }
3
  • Visual Studio tiene la opcion para pegar un json o xml y transformarlo en clases. Commented el 30 abr. 2020 a las 23:06
  • Cuando utilizas jsonutils.com la misma te deja configurar una serie de opciones, creo que lo que te falta es darle ckeck a Pascal Case y en la lista de Property Attributes selecionar JsonProperty o DataMember, cual sea tu caso.
    – dlr
    Commented el 30 abr. 2020 a las 23:47
  • Te esta forma todas las propiedades que lleven un guion bajo, por ejemplo (IsHidden de la clase abilities en realidad en el json es is_hidden) estaran en el atributo de la propiedad y el serializador sabra cual debe utilizar.
    – dlr
    Commented el 30 abr. 2020 a las 23:50

1 respuesta 1

1

Tu modelo parece ser incorrecto. Prueba con este modelo que he generado esta herramienta online.

 public partial class PokemonDetail
    {
        [JsonProperty("abilities")]
        public Ability[] Abilities { get; set; }

        [JsonProperty("base_experience")]
        public long BaseExperience { get; set; }

        [JsonProperty("forms")]
        public Species[] Forms { get; set; }

        [JsonProperty("game_indices")]
        public GameIndex[] GameIndices { get; set; }

        [JsonProperty("height")]
        public long Height { get; set; }

        [JsonProperty("held_items")]
        public HeldItem[] HeldItems { get; set; }

        [JsonProperty("id")]
        public long Id { get; set; }

        [JsonProperty("is_default")]
        public bool IsDefault { get; set; }

        [JsonProperty("location_area_encounters")]
        public Uri LocationAreaEncounters { get; set; }

        [JsonProperty("moves")]
        public Move[] Moves { get; set; }

        [JsonProperty("name")]
        public string Name { get; set; }

        [JsonProperty("order")]
        public long Order { get; set; }

        [JsonProperty("species")]
        public Species Species { get; set; }

        [JsonProperty("sprites")]
        public Sprites Sprites { get; set; }

        [JsonProperty("stats")]
        public Stat[] Stats { get; set; }

        [JsonProperty("types")]
        public TypeElement[] Types { get; set; }

        [JsonProperty("weight")]
        public long Weight { get; set; }
    }

    public partial class Ability
    {
        [JsonProperty("ability")]
        public Species AbilityAbility { get; set; }

        [JsonProperty("is_hidden")]
        public bool IsHidden { get; set; }

        [JsonProperty("slot")]
        public long Slot { get; set; }
    }

    public partial class Species
    {
        [JsonProperty("name")]
        public string Name { get; set; }

        [JsonProperty("url")]
        public Uri Url { get; set; }
    }

    public partial class GameIndex
    {
        [JsonProperty("game_index")]
        public long GameIndexGameIndex { get; set; }

        [JsonProperty("version")]
        public Species Version { get; set; }
    }

    public partial class HeldItem
    {
        [JsonProperty("item")]
        public Species Item { get; set; }

        [JsonProperty("version_details")]
        public VersionDetail[] VersionDetails { get; set; }
    }

    public partial class VersionDetail
    {
        [JsonProperty("rarity")]
        public long Rarity { get; set; }

        [JsonProperty("version")]
        public Species Version { get; set; }
    }

    public partial class Move
    {
        [JsonProperty("move")]
        public Species MoveMove { get; set; }

        [JsonProperty("version_group_details")]
        public VersionGroupDetail[] VersionGroupDetails { get; set; }
    }

    public partial class VersionGroupDetail
    {
        [JsonProperty("level_learned_at")]
        public long LevelLearnedAt { get; set; }

        [JsonProperty("move_learn_method")]
        public Species MoveLearnMethod { get; set; }

        [JsonProperty("version_group")]
        public Species VersionGroup { get; set; }
    }

    public partial class Sprites
    {
        [JsonProperty("back_default")]
        public Uri BackDefault { get; set; }

        [JsonProperty("back_female")]
        public object BackFemale { get; set; }

        [JsonProperty("back_shiny")]
        public Uri BackShiny { get; set; }

        [JsonProperty("back_shiny_female")]
        public object BackShinyFemale { get; set; }

        [JsonProperty("front_default")]
        public Uri FrontDefault { get; set; }

        [JsonProperty("front_female")]
        public object FrontFemale { get; set; }

        [JsonProperty("front_shiny")]
        public Uri FrontShiny { get; set; }

        [JsonProperty("front_shiny_female")]
        public object FrontShinyFemale { get; set; }
    }

    public partial class Stat
    {
        [JsonProperty("base_stat")]
        public long BaseStat { get; set; }

        [JsonProperty("effort")]
        public long Effort { get; set; }

        [JsonProperty("stat")]
        public Species StatStat { get; set; }
    }

    public partial class TypeElement
    {
        [JsonProperty("slot")]
        public long Slot { get; set; }

        [JsonProperty("type")]
        public Species Type { get; set; }
    }
}

También he corregido la declaración de tu método ya que el json no es una lista sino es un objeto que contiene más datos.

public async Task<PokemonDetail> GetPokemonDetail(string u) 
{
  var uri = u;
  HttpClient client = new HttpClient();
  var respPokeApi = await client.GetAsync(uri);
  var pokemondetail =  PokemonDetail();

  if (respPokeApi.IsSuccessStatusCode) {
    var respContent = await respPokeApi.Content.ReadAsStringAsync();
    pokemondetail = JsonConvert.DeserializeObject<PokemonDetail>(respContent);
  }

  return pokemondetail;
}

Tu Respuesta

By clicking “Publica tu respuesta”, you agree to our terms of service and acknowledge you have read our privacy policy.

¿No es la respuesta que buscas? Examina otras preguntas con la etiqueta o formula tu propia pregunta.