C# 将来自SkyDrive的JSON响应反序列化到自定义类

C# 将来自SkyDrive的JSON响应反序列化到自定义类,c#,json,windows-phone-8,windows-phone,onedrive,C#,Json,Windows Phone 8,Windows Phone,Onedrive,我想将来自LiveConnectClient.GetAsyncme/skydrive/files的JSON响应反序列化到自定义类,以确定skydrive根目录上是否存在特定文件夹。我从skydrive获得json结果,并使用json2csharp.com获得类结构。然后,我使用Json.net的DeserializeObject方法将Json反序列化为类结构。但它在执行期间抛出异常。我没有转换json结果就得到了想要的结果。但我想知道哪里出了问题,以及如何将其转换为自定义类。代码如下所示 pri

我想将来自LiveConnectClient.GetAsyncme/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);
        ...
    }
信息 与“Newtonsoft.Json.JsonConvert.DeserializeObjectstring”匹配的最佳重载方法

有一些无效的参数

堆栈跟踪

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()
来自JSON2Charp的类

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; }
}

有人能告诉我这里出了什么问题以及如何解决吗。谢谢

filelist是否为string类型?消息“Newtonsoft.Json.JsonConvert.DeserializeObjectstring”的最佳重载方法匹配具有一些无效参数必须表示“filelist”不是预期的类型。。。文件列表不是一个字符串。我使用var是因为我不知道结果的类型。我明白了,因为fileList不是字符串JsonConvert.DeserializeObjectfileList;抛出异常。那么我如何获取json字符串呢?skyResult是一种动态类型。如何从中提取json字符串?您是否尝试过ToString?请尝试从调试器中检查文件列表的属性。@ChrisK-在skyResult.data上使用ToString会导致此异常Newtonsoft.Json.JsonReaderException消息:在分析值时遇到意外字符:S。路径,第0行,位置0。
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()
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; }
}