将来自SkyDrive的JSON响应反序列化为自定义类

时间:2013-11-22 13:04:33

标签: c# json windows-phone-8 windows-phone onedrive

我想将来自LiveConnectClient.GetAsync(“me / skydrive / files”)的JSON响应反序列化为自定义类,以查明skydrive根目录中是否存在特定文件夹。我从skydrive获得了json结果,并使用json2csharp.com来获取类结构。然后我使用Json.net的DeserializeObject方法将json反序列化为类结构。但它在执行期间抛出异常。我没有转换json结果就得到了理想的结果。但我想知道出了什么问题以及如何将其转换为我的自定义类。代码如下:

private async void btnFldrStruct_Click(object sender, RoutedEventArgs e)
    {
        LiveOperationResult opResult = await client.GetAsync("me/skydrive/files");
        dynamic skyResult = opResult.Result;
        var fileList = skyResult.data;
        SkyDrive skydrive = JsonConvert.DeserializeObject<SkyDrive>(fileList);
        ...
    }

引发异常
SkyDrive skydrive = JsonConvert.DeserializeObject<SkyDrive>(fileList);

例外是

 Microsoft.CSharp.RuntimeBinder.RuntimeBinderException

信息     'Newtonsoft.Json.JsonConvert.DeserializeObject(string)'

的最佳重载方法匹配

有一些无效的参数

堆栈跟踪

at CallSite.Target(Closure , CallSite , Type , Object )
at System.Dynamic.UpdateDelegates.UpdateAndExecute2[T0,T1,TRet](CallSite site, T0 arg0, T1 arg1)
at SkyDriveTestApp.MainPage.<btnFldrStruct_Click>d__26.MoveNext()

json2csharp中的类

public class From
{
    public string name { get; set; }
    public string id { get; set; }
}

public class SharedWith
{
    public string access { get; set; }
}

public class Image
{
    public int height { get; set; }
    public int width { get; set; }
    public string source { get; set; }
    public string type { get; set; }
}

public class Datum
{
    public string id { get; set; }
    public From from { get; set; }
    public string name { get; set; }
    public string description { get; set; }
    public string parent_id { get; set; }
    public int size { get; set; }
    public string upload_location { get; set; }
    public int comments_count { get; set; }
    public bool comments_enabled { get; set; }
    public bool is_embeddable { get; set; }
    public int count { get; set; }
    public string link { get; set; }
    public string type { get; set; }
    public SharedWith shared_with { get; set; }
    public string created_time { get; set; }
    public string updated_time { get; set; }
    public string client_updated_time { get; set; }
    public int? tags_count { get; set; }
    public bool? tags_enabled { get; set; }
    public string picture { get; set; }
    public string source { get; set; }
    public List<Image> images { get; set; }
    public string when_taken { get; set; }
    public int? height { get; set; }
    public int? width { get; set; }
    public object location { get; set; }
    public object camera_make { get; set; }
    public object camera_model { get; set; }
    public int? focal_ratio { get; set; }
    public int? focal_length { get; set; }
    public int? exposure_numerator { get; set; }
    public int? exposure_denominator { get; set; }
}

public class SkyDrive
{
    public List<Datum> data { get; set; }
}

有人可以告诉我这里有什么问题,以及如何解决它。谢谢

0 个答案:

没有答案