【发布时间】:2017-05-16 15:58:16
【问题描述】:
我正在尝试使用 JsonConver.DeserializeObject 反序列化一些 json。但是它不适用于我正在使用的api中的一些json。这是一个不起作用的链接:https://api.pokemontcg.io/v1/cards?setCode=smp
这是一个有效的链接。 https://api.pokemontcg.io/v1/cards?setCode=sm2
我不确定为什么它有时有效,有时无效。从中出来的数据非常相似,只是不同的卡片。 代码如下:
public static async Task<T> GetDataAsync<T>(this HttpClient client, string address, string querystring)
where T : class
{
var uri = address;
if (!string.IsNullOrEmpty(querystring))
{
uri += querystring;
}
var httpMessage = await client.GetStringAsync(uri);
var jsonObject = JsonConvert.DeserializeObject<T>(httpMessage);
return jsonObject;
}
现在我的卡片课
namespace CardAppReal.Lib.Models
{
public class Card
{
public string id { get; set; }
public string name { get; set; }
public string imageUrl { get; set; }
public string imageUrlHiRes { get; set; }
public string supertype { get; set; } // if pokemon, trainer or energy
public string setcode { get; set; }
public int number { get; set; }
public string set { get; set; }
}
}
有根
using System.Collections.Generic;
using CardAppReal.Lib.Models;
namespace CardAppReal.Lib.Entities
{
public class RootCard
{
public List<Card> cards { get; set; }
}
}
如果你能帮助我,我会觉得很棒。
【问题讨论】:
-
当它失败时,它会给你一个异常或错误信息吗?
-
@Jason 不,它没有,它只是让我的 jsonObject 为空。
-
我建议您仔细比较一个工作结果和一个非工作结果,并找出不同之处。
-
我会将 json 反序列化的内容记录为空对象
标签: c# android json xamarin xamarin.android