Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/283.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C#Json反序列化失败_C#_Arrays_Json_Serialization - Fatal编程技术网

C#Json反序列化失败

C#Json反序列化失败,c#,arrays,json,serialization,C#,Arrays,Json,Serialization,我正在尝试制作一个可以通过JSON rest api C#显示本地电视指南的应用程序,但在JSON响应的反序列化方面存在一些问题 我现在在json调用中只是数组中的intrest,我不拥有api服务 我收到以下错误消息: Newtonsoft.Json.Json.JsonSerializationException类型的异常在Newtonsoft.Json.DLL中发生,但未在用户代码中处理 其他信息:无法将当前JSON对象(例如{“name”:“value”})反序列化为类型“System.C

我正在尝试制作一个可以通过JSON rest api C#显示本地电视指南的应用程序,但在JSON响应的反序列化方面存在一些问题

我现在在json调用中只是数组中的intrest,我不拥有api服务

我收到以下错误消息:

Newtonsoft.Json.Json.JsonSerializationException类型的异常在Newtonsoft.Json.DLL中发生,但未在用户代码中处理

其他信息:无法将当前JSON对象(例如{“name”:“value”})反序列化为类型“System.Collections.Generic.List`1[TDC_Play_TV_Mobil.superclass2+Now]”,因为该类型需要JSON数组(例如[1,2,3])才能正确反序列化

若要修复此错误,请将JSON更改为JSON数组(例如[1,2,3]),或更改反序列化类型,使其成为可以从JSON对象反序列化的正常.NET类型(例如,不是integer之类的基元类型,也不是数组或列表之类的集合类型)。还可以将JsonObjectAttribute添加到类型中,以强制它从JSON对象反序列化

“现在”路径,第1行,位置7

我的职能:

private HttpClient client;

   public async Task<List<superclass2.Now>> GetComments()
   {
       client = new HttpClient();
      var response = await client.GetAsync(new Uri("http://api.yousee.tv/rest/tvguide/nowandnext/"));
       if (response.IsSuccessStatusCode)
       {
           
           string json = await response.Content.ReadAsStringAsync();

           System.Diagnostics.Debug.WriteLine(json);
           var task = Task.Factory.StartNew(() => JsonConvert.DeserializeObject<List<superclass2.Now>>(json));

           var value = await task;
         //  List<superclass2.Now> comments = Newtonsoft.Json.JsonConvert.DeserializeObject<List<superclass2.Now>>(await json);
          System.Diagnostics.Debug.WriteLine("Comments er lavet");
          return value;

       }
       else
       {
           throw new Exception("Errorhandling message");

       }
        

   }
私有HttpClient;
公共异步任务GetComments()
{
client=新的HttpClient();
var response=await client.GetAsync(新Uri(“http://api.yousee.tv/rest/tvguide/nowandnext/"));
if(响应。IsSuccessStatusCode)
{
string json=wait response.Content.ReadAsStringAsync();
System.Diagnostics.Debug.WriteLine(json);
var task=task.Factory.StartNew(()=>JsonConvert.DeserializeObject(json));
var值=等待任务;
//List comments=Newtonsoft.Json.JsonConvert.DeserializeObject(等待Json);
系统、诊断、调试、写行(“注释er-lavet”);
返回值;
}
其他的
{
抛出新异常(“错误处理消息”);
}
}
我的类文件:

public class superclass2
{
public class Logos
   {
       public string small { get; set; }
       public string large { get; set; }
       public string small_seapp { get; set; }
       public string large_seapp { get; set; }
       public string extralarge { get; set; }
       public string super { get; set; }
       public string mega { get; set; }
       public string netgem { get; set; }
       public string svg { get; set; }
   }

   public class ChannelInfo
   {
       public string name { get; set; }
       public string shortname { get; set; }
       public string logo_image_prefix { get; set; }
       public Logos logos { get; set; }
       public int archivedays { get; set; }
       public string channelcolor { get; set; }
   }

   public class FormattedDate
   {
       public string time_begin { get; set; }
       public string time_end { get; set; }
       public string date { get; set; }
   }

   public class ImagesSixteenbynine
   {
       public string large { get; set; }
       public string medium { get; set; }
       public string small { get; set; }
   }

   public class ImagesFourbythree
   {
       public string large { get; set; }
       public string small { get; set; }
   }

   public class ImagesSquare
   {
       public string large { get; set; }
       public string medium { get; set; }
       public string small { get; set; }
   }

   public class Now
   {
       public int id { get; set; }
       public int dvb_id { get; set; }
       public int channel { get; set; }
       public ChannelInfo channel_info { get; set; }
       public string orgtitle { get; set; }
       public string cast { get; set; }
       public string directors { get; set; }
       public string series_info { get; set; }
       public int series_id { get; set; }
       public string series_name { get; set; }
       public bool allowseriesrecording { get; set; }
       public int totalinarchive { get; set; }
       public int popularity_score { get; set; }
       public int totalupcoming { get; set; }
       public int category { get; set; }
       public int subcategory { get; set; }
       public string category_string { get; set; }
       public string subcategory_string { get; set; }
       public int begin { get; set; }
       public object actual_begin { get; set; }
       public int end { get; set; }
       public int actual_end { get; set; }
       public int tvdate { get; set; }
       public FormattedDate formatted_date { get; set; }
       public string title { get; set; }
       public string description { get; set; }
       public bool archive { get; set; }
       public bool scrubbingallowed { get; set; }
       public int expiresfromarchive { get; set; }
       public bool startover { get; set; }
       public string imageprefix { get; set; }
       public ImagesSixteenbynine images_sixteenbynine { get; set; }
       public ImagesFourbythree images_fourbythree { get; set; }
       public ImagesSquare images_square { get; set; }
       public List<object> decorations { get; set; }
   }

   public class Logos2
   {
       public string small { get; set; }
       public string large { get; set; }
       public string small_seapp { get; set; }
       public string large_seapp { get; set; }
       public string extralarge { get; set; }
       public string super { get; set; }
       public string mega { get; set; }
       public string netgem { get; set; }
       public string svg { get; set; }
   }

   public class ChannelInfo2
   {
       public string name { get; set; }
       public string shortname { get; set; }
       public string logo_image_prefix { get; set; }
       public Logos2 logos { get; set; }
       public int archivedays { get; set; }
       public string channelcolor { get; set; }
   }

   public class FormattedDate2
   {
       public string time_begin { get; set; }
       public string time_end { get; set; }
       public string date { get; set; }
   }

   public class ImagesSixteenbynine2
   {
       public string large { get; set; }
       public string medium { get; set; }
       public string small { get; set; }
   }

   public class ImagesFourbythree2
   {
       public string large { get; set; }
       public string small { get; set; }
   }

   public class ImagesSquare2
   {
       public string large { get; set; }
       public string medium { get; set; }
       public string small { get; set; }
   }

   public class Next
   {
       public int id { get; set; }
       public int dvb_id { get; set; }
       public int channel { get; set; }
       public ChannelInfo2 channel_info { get; set; }
       public string orgtitle { get; set; }
       public string cast { get; set; }
       public string directors { get; set; }
       public string series_info { get; set; }
       public int series_id { get; set; }
       public string series_name { get; set; }
       public bool allowseriesrecording { get; set; }
       public int totalinarchive { get; set; }
       public int popularity_score { get; set; }
       public int totalupcoming { get; set; }
       public int category { get; set; }
       public int subcategory { get; set; }
       public string category_string { get; set; }
       public string subcategory_string { get; set; }
       public int begin { get; set; }
       public int actual_begin { get; set; }
       public int end { get; set; }
       public int actual_end { get; set; }
       public int tvdate { get; set; }
       public FormattedDate2 formatted_date { get; set; }
       public string title { get; set; }
       public string description { get; set; }
       public bool archive { get; set; }
       public bool scrubbingallowed { get; set; }
       public int expiresfromarchive { get; set; }
       public bool startover { get; set; }
       public string imageprefix { get; set; }
       public ImagesSixteenbynine2 images_sixteenbynine { get; set; }
       public ImagesFourbythree2 images_fourbythree { get; set; }
       public ImagesSquare2 images_square { get; set; }
       public List<object> decorations { get; set; }
   }

   public class RootObject
   {
       public List<Now> now { get; set; }
       public List<Next> next { get; set; }
   }

}
公共类超类2
{
公共类标识
{
公共字符串小{get;set;}
公共字符串大{get;set;}
公共字符串small_seapp{get;set;}
公共字符串大\u seapp{get;set;}
公共字符串超大{get;set;}
公共字符串super{get;set;}
公共字符串mega{get;set;}
公共字符串netgem{get;set;}
公共字符串svg{get;set;}
}
公共类ChannelInfo
{
公共字符串名称{get;set;}
公共字符串短名称{get;set;}
公共字符串logo\u image\u前缀{get;set;}
公共徽标徽标{get;set;}
public int archivedays{get;set;}
公共字符串channelcolor{get;set;}
}
公共类格式化日期
{
公共字符串时间\u开始{get;set;}
公共字符串时间_end{get;set;}
公共字符串日期{get;set;}
}
公共类ImagesSixtenBynine
{
公共字符串大{get;set;}
公共字符串媒体{get;set;}
公共字符串小{get;set;}
}
公共类图像城市树
{
公共字符串大{get;set;}
公共字符串小{get;set;}
}
公共类ImagesSquare
{
公共字符串大{get;set;}
公共字符串媒体{get;set;}
公共字符串小{get;set;}
}
现在公开课
{
公共int id{get;set;}
public int dvb_id{get;set;}
公共int通道{get;set;}
公共频道信息频道信息{get;set;}
公共字符串orgtitle{get;set;}
公共字符串强制转换{get;set;}
公共字符串控制器{get;set;}
公共字符串系列_info{get;set;}
公共int系列_id{get;set;}
公共字符串系列_name{get;set;}
公共布尔允许体验记录{get;set;}
公共整数totalinarchive{get;set;}
公共int受欢迎程度_分数{get;set;}
公共整数{get;set;}
公共int类{get;set;}
公共int子类别{get;set;}
公共字符串类别_字符串{get;set;}
公共字符串子类别_字符串{get;set;}
公共int开始{get;set;}
公共对象实际开始{get;set;}
公共int end{get;set;}
公共int实际值_end{get;set;}
public int tvdate{get;set;}
public FormattedDate formatted_date{get;set;}
公共字符串标题{get;set;}
公共字符串说明{get;set;}
公共布尔存档{get;set;}
公共布尔擦洗允许{get;set;}
public int expiresfromarchive{get;set;}
公共bool startover{get;set;}
公共字符串imageprefix{get;set;}
公共图像SixtenBynine图像_sixtenBynine{get;set;}
公共映像城市三个映像\u fourbythree{get;set;}
公共图像方形图像{get;set;}
公共列表装饰{get;set;}
}
公共类标识2
{
公共字符串小{get;set;}
公共字符串大{get;set;}
公共字符串small_seapp{get;set;}
公共字符串大\u seapp{get;set;}
公共字符串超大{get;set;}
公共字符串super{get;set;}
公共字符串mega{get;set;}
公共字符串netgem{get;set;}
公共字符串svg{get;set;}
}
公共类频道信息2
{
公共字符串名称{get;set;}
公共字符串短名称{get;set;}
公共字符串logo\u image\u前缀{get;set;}
公共Logos2 logos{get;set;}
public int archivedays{get;set;}
公共字符串channelcolor{get;set;}
}
公共类FormattedDate2
{
公共字符串时间\u开始{get;set;}
公共字符串时间_end{get;set;}
公共字符串日期{get;set;}
}
公共类ImagesXtenBynine2
{
公共字符串大{get;s
    public async Task<List<superclass2.Now>> GetComments()    
    {
        client = new HttpClient();
        var response = await client.GetAsync(new Uri("http://api.yousee.tv/rest/tvguide/nowandnext/"));
        if (response.IsSuccessStatusCode)
        {
            string json = await response.Content.ReadAsStringAsync();
            System.Diagnostics.Debug.WriteLine(json);
            var task = Task.Factory.StartNew(() => JsonConvert.DeserializeObject<superclass2.RootObject>(json));

            var value = await task;
            System.Diagnostics.Debug.WriteLine("Comments er lavet");
            return (value == null ? null : value.now);
        }
        else
        {
            throw new Exception("Errorhandling message");
        }
    }