我的查询返回FirebaseObjects列表:在Xamarin火力地堡查询失败
IReadOnlyCollection<Firebase.Xamarin.Database.FirebaseObject<object>> items = await firebase.Child("product").OnceAsync<object>();
但我想这样做:
Product product = await firebase.Child("product").OnceAsync<Product>();
我可以改变我的查询,使其工作,或者是这个它是如何工作的? 我的意思是,我将总是找回列表,还是可以直接反序列化到我的Product对象?
JSON的完整结构
{
"product1": {
"pname": "Peppermint Kiss",
"teaType": "Black Tea",
"company": "PersnickeTea",
"packSize": {
"teabag": [
{
"qty": 1,
"price": 1.5,
"tImage": "singleCup.jpg"
},
{
"qty": 5,
"tinPrice": 6.95,
"tImage": "blackTeaTin.jpg"
},
{
"qty": 8,
"price": 10,
"tImage": "blackTeabox.jpg"
},
{
"qty": 12,
"boxPrice": 14.95,
"tImage": "trayBox.jpg"
}
],
"looseLeaf": [
{
"qty": 46,
"price": 7.95,
"tImage": "mintKissPak.jpg"
}
]
},
"ingredients": [
"black tea",
"peppermint leaves",
"candy pieces",
"organic peppermint oil",
"natural creme flavor",
"raspberry leaves",
"red clover",
"anise seed"
],
"prepMethod": [
"infuser",
"teabags",
"strainer",
"iced"
]
},
"product2": {
"pname": "Spearmint Kiss",
"teaType": "Black Tea",
"company": "PersnickeTea",
"packSize": {
"teabag": [
{
"qty": 1,
"price": 1.5,
"tImage": "singleCup.jpg"
},
{
"qty": 5,
"tinPrice": 6.95,
"tImage": "blackTeaTin.jpg"
},
{
"qty": 8,
"price": 10,
"tImage": "blackTeabox.jpg"
},
{
"qty": 12,
"boxPrice": 14.95,
"tImage": "trayBox.jpg"
}
],
"looseLeaf": [
{
"qty": 46,
"price": 7.95,
"tImage": "mintKissPak.jpg"
}
]
},
"ingredients": [
"black tea",
"peppermint leaves",
"candy pieces",
"organic peppermint oil",
"natural creme flavor",
"raspberry leaves",
"red clover",
"anise seed"
],
"prepMethod": [
"infuser",
"teabags",
"strainer",
"iced"
]
},
"product3": {
"pname": "Mintymint Kiss",
"teaType": "Black Tea",
"company": "PersnickeTea",
"packSize": {
"teabag": [
{
"qty": 1,
"price": 1.5,
"tImage": "singleCup.jpg"
},
{
"qty": 5,
"tinPrice": 6.95,
"tImage": "blackTeaTin.jpg"
},
{
"qty": 8,
"price": 10,
"tImage": "blackTeabox.jpg"
},
{
"qty": 12,
"boxPrice": 14.95,
"tImage": "trayBox.jpg"
}
],
"looseLeaf": [
{
"qty": 46,
"price": 7.95,
"tImage": "mintKissPak.jpg"
}
]
},
"ingredients": [
"black tea",
"peppermint leaves",
"candy pieces",
"organic peppermint oil",
"natural creme flavor",
"raspberry leaves",
"red clover",
"anise seed"
],
"prepMethod": [
"infuser",
"teabags",
"strainer",
"iced"
]
}
}
与关系数据库的比较是有道理的,我显然没有意识到这是Firebase的。然而,var products =等待firebase.Child(“product”)。OnceAsync(); “我无法投射或从System.String转换为LayoutTutorial.model.Product” –
ezaspi
不,Firebase是一个非关系数据库,我只是做了比较,以便您能够理解您的查询发生了什么。您是否可以更新显示您在Firebase中的产品表结构的原始帖子? – apineda
我加了json。有3个产品,产品1,产品2和产品3。我可以像这样获取每个产品:var items = await firebase.Child(“product1”)。OnceAsync