繁体   English   中英

.NET C# 从 Firebase 检索数据

[英].NET C# retrieving data from Firebase

从 Firebase 上托管的数据库检索数据到我的 .net 应用程序时,我遇到了一些问题。 在调试时,我注意到response包含[{"Description":"desccc","Id":2},{"Description":"asdfasdf","Id":1}]并且这是我数据库中的唯一记录,所以我想这一刻一切都很好。 不幸的是,当尝试将此数据放入result它会引发如下错误:

{System.MissingMethodException: 没有为此对象定义无参数构造函数。 在 System.Activator.CreateInstanceT at RestSharp.Deserializers.JsonDeserializer.Deserialize[T](IRestResponse response) at Rate_Your_Game.Controllers.GameController.GetGames() 在 PATH/Rate Your Game\\Controllers\\GameController.cs:line 49}

[HttpGet("[action]")]
public async Task<Game[]> GetGames()
{
    try
    {
        client = new FireSharp.FirebaseClient(config);
        FirebaseResponse response = await client.GetTaskAsync("Games/");
        Game[] result = response.ResultAs<Game[]>();
        return result;
    }
    catch (Exception e)
    {
        throw e;
    }
}

这是我的游戏课

public class Game
    {
        public Game() {}

        public int Id { get; set; }
        public string Description{ get; set; }    
        
    }

Game类需要具有无参数构造函数。

public class Game {
     public Game(){
     }

     ....
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM