且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

无法将JSON对象反序列化为类型'System.Collections.Generic.List'

更新时间:2023-01-17 21:24:26

您的JSON数据具有两个主要元素 metadata results .并且根据您的类结构,流派类也具有相同的结构.但是在您的代码中,您尝试将结构反序列化为 Results ,这就是您收到错误的原因.
您应该尝试将序列化反序列化为 Genres 类.
新代码将类似于

Your JSON data has two main elements metadata and results. And according to you class structure, the Genres class also has the same structure. But in your code you are trying to de-serialize the structure to Results, thats why you are getting the error.
You should try to de-serialize to Genres class.
The new code will be something like


void beatportTest_GetDataCompleted(object sender, DownloadStringCompletedEventArgs e)
{
   try
   {
      Genres data = JsonConvert.DeserializeObject(e.Result);
      // for-each loop to display data
   }
   catch(Exception ex)
   {
   }
}