c#dynamodb queryAsync结果不正确显示(更新:固定)

发布于 2025-02-11 19:57:04 字数 1513 浏览 2 评论 0原文

我觉得我犯了一个非常基本的错误。这是我第一次将C#与DynamoDB一起使用,因此一切都非常新。我想问的问题是如何显示结果。我尝试将其保存在文件中,但我得到的只是

system.threading.tasks.task 1 [system.collections.generic.ienumosity 1 [connectdb.tables.reply]]


我也有首先将其转换为字符串。如果我不这样说

cs0029:无法隐式转换类型'System.Threading.tasks.task< system.Collections.generic.Generic.IENUMASTER< connectdb.tables.reply>>'''到“字符串”

public async Task<IEnumerable<Reply>> Get(string Id = "001")
{
         AmazonDynamoDBClient client = new AmazonDynamoDBClient(awsAccessKeyId: "ihgowijrlejsafjaklsjgo", awsSecretAccessKey: "hiowajflekahglajsgaijkgilw", Amazon.RegionEndpoint.ap-east-1);
         DynamoDBContext context = new DynamoDBContext(client);

         return await context.QueryAsync<Reply>(Id).GetRemainingAsync();
}

更新:修复了

这是我修复的方式。我显示错了,谢谢 ermiya eskandary

public Getitems new_obj = new Getitems();
protected async void buttonclick(object sender, EventArgs e)
{

        string path = @"file.json";
        StreamWriter OurStream;
        OurStream = File.CreateText(path);
        var results = await new_obj.Get();
        var options = new JsonSerializerOptions { WriteIndented = true };
        string jsonString = JsonSerializer.Serialize(results, options);
        OurStream.WriteLine(jsonString);     
        OurStream.Close();

}

I feel I'm making a very elementary mistake. Its my first time using C# with DynamoDB so everything is very new. The question I want to ask is how do I display the result. I tried saving it in a file, but all I get is

System.Threading.Tasks.Task1[System.Collections.Generic.IEnumerable1[ConnectDB.Tables.Reply]]

Also I'm having to convert it to string first. If I don't it says

CS0029: Cannot implicitly convert type 'System.Threading.Tasks.Task<System.Collections.Generic.IEnumerable<ConnectDB.Tables.Reply>>' to 'string'

public async Task<IEnumerable<Reply>> Get(string Id = "001")
{
         AmazonDynamoDBClient client = new AmazonDynamoDBClient(awsAccessKeyId: "ihgowijrlejsafjaklsjgo", awsSecretAccessKey: "hiowajflekahglajsgaijkgilw", Amazon.RegionEndpoint.ap-east-1);
         DynamoDBContext context = new DynamoDBContext(client);

         return await context.QueryAsync<Reply>(Id).GetRemainingAsync();
}

Update: Fixed

This is how I fixed it. I was displaying it wrong, thanks Ermiya Eskandary.

public Getitems new_obj = new Getitems();
protected async void buttonclick(object sender, EventArgs e)
{

        string path = @"file.json";
        StreamWriter OurStream;
        OurStream = File.CreateText(path);
        var results = await new_obj.Get();
        var options = new JsonSerializerOptions { WriteIndented = true };
        string jsonString = JsonSerializer.Serialize(results, options);
        OurStream.WriteLine(jsonString);     
        OurStream.Close();

}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文