J'essaie d'accéder aux tags individuels de l'API Web JSON. si vous regardez mon message de débogage vous pouvez voir que chaque balise est affichée avec les données correctes dans « jsonMessage », mais quand je reviens « résultat » chaque balise est définie sur null:C# - Appelez l'API Web JSON et obtenez des données
Alors, comment je obtenir toutes les balises de jsonMessage
revenir donc je peux taper par exemple texblock.text = card.name;
et ainsi de suite
public async static Task<Card> GetCard()
{
string url = String.Format("https://api.magicthegathering.io/v1/cards/386616");
HttpClient client = new HttpClient();
//client.BaseAddress = new Uri(url);
var response = await client.GetAsync(url);
var jsonMessage = await response.Content.ReadAsStringAsync();
var serializer = new DataContractJsonSerializer(typeof(Card));
var ms = new MemoryStream(Encoding.UTF8.GetBytes(jsonMessage));
var result = (Card)serializer.ReadObject(ms);
return result;
}
Voici la classe Cartes:
public class Card
{
public string name { get; set; }
public string manaCost { get; set; }
public int cmc { get; set; }
public List<string> colors { get; set; }
public string type { get; set; }
public List<string> types { get; set; }
public List<string> subtypes { get; set; }
public string rarity { get; set; }
public string set { get; set; }
public string text { get; set; }
public string artist { get; set; }
public string number { get; set; }
public string power { get; set; }
public string toughness { get; set; }
public string layout { get; set; }
public int multiverseid { get; set; }
public string imageUrl { get; set; }
public List<Ruling> rulings { get; set; }
public List<ForeignName> foreignNames { get; set; }
public List<string> printings { get; set; }
public string originalText { get; set; }
public string originalType { get; set; }
public List<Legality> legalities { get; set; }
public string id { get; set; }
}