c#dynamodb queryAsync结果不正确显示(更新:固定)
我觉得我犯了一个非常基本的错误。这是我第一次将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.Task
1[System.Collections.Generic.IEnumerable
1[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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论