{
"Cats": [
{
"Name": "Max",
"Color": "Brown"
},
{
"Name": "Cherry",
"Color": "Black"
}
],
"Owners": [
{
"Name": "Tom",
"Cat": "Max"
},
{
"Name": "Cindy",
"Cat": "Cherry"
}
]
}
而不是获取汤姆猫的字符串值,然后执行第二个操作来获取猫的颜色,是否可以反序列化此 JSON,以便我可以执行以下操作:
var tomsCatsColor = Rootobject.Owners[0].Cat.Color;
您可以为用户提供一个 cat 标识符,如下所示:
{
"Cats": [
{
"Name": "Max",
"Color": "Brown"
},
{
"Name": "Cherry",
"Color": "Black"
}
],
"Owners": [
{
"Name": "Tom",
"Cat": 0
},
{
"Name": "Cindy",
"Cat": 1
}
]
}
var tomsCatsColor = Rootobject.Cats[Rootobject.Owners[0].Cat].Color;