c# - 如何在 asp.net core mvc 网站上显示来自 firebase 的对象?
问题描述
我正在用 asp.net core MVC 制作一个网站,我应该能够在其中显示商品库存。
我创建了一个 firebase 实时数据库,我应该可以在其中添加更多商品并在网站上显示商品。我现在可以写入数据库以添加商品并且已正确添加。我的问题是我无法从数据库中正确获取数据。
这是在 HomeController 内部:
Merchandise test = new Merchandise("Løbsmærker", 25, test2);
var firebaseClient = new FirebaseClient("https://invictuslagerstyring.firebaseio.com/");
var result = await firebaseClient.Child("Name " + test.Name).PostAsync(test);
var ud = await firebaseClient.Child("Name " + test.Name).Child("Name").OnceAsync<Merchandise>();
这是商品构造函数:
public Merchandise(String name, double salePrice, Boolean[] size)
{
merchID = ++amountOfMerch;
this.name = name;
this.salePrice = salePrice;
this.size = new Boolean[size.Length];
if (size.Length > 0)
{
this.size = new Boolean[amountOfSizes];
this.size = size;
}
}
我希望输出“Løbsmærker”,但实际输出是Firebase.Database.FirebaseObject1[Lagerstyring.Controllers.Merchandise][]
解决方案
我怀疑你运行后:
var ud = await firebaseClient.Child("Name " + test.Name).Child("Name").OnceAsync<Merchandise>();
您将上述变量分配给文本字段或其他内容。哪个调用ToString()
方法。而是创建一个新变量并分配Name
给它。
推荐阅读
- json - 如何与需要 Flutter 密钥的 REST API 交互?
- graphql - GraphQL 解析器 - 何时使解析器函数异步?
- mysql - 同一事务中的多个无序读取查询会返回相同的结果吗?
- c++ - 从文件中获取并输出二进制数据
- react-native - 解决方法博览会反应原生网络闪屏
- java - Java - 对象的变量定义
- java - openJdk 升级到 8u292 会破坏我的 aosp 构建系统吗?
- python - 有没有办法检测 Python 项目中静态弃用的模块?
- ocaml - 如何在 OCaml 中让 rec n 读取 read_int
- prometheus - 是否可以在 Whatsapp 或 Telegram 等即时消息中使用 Prometheus 警报?