我是Firebase的新手。我已经设置了我的数据库,并且工作正常。但是,有一些问题。我的数据库为JSON,如下所示。请看看它。
{
"Cohesion" :
{
"Situational" :
{
"Home" :
{
"Chelsea" :
{
"Counter_Attack" : 0,
"Open_Play" : 4,
"Penalty" : 1,
"Set_Piece" : 0,
"Own_goal" : 0
},
"Liverpool" :
{
"Counter_Attack" : 0,
"Open_Play" : 4,
"Penalty" : 0,
"Set_Piece" : 0,
"Own_goal" : 0
},
"Burnley" :
{
"Counter_Attack" : 0,
"Open_Play" : 3,
"Penalty" : 0,
"Set_Piece" : 0,
"Own_goal" : 0
},
"Arsenal" :
{
"Counter_Attack" : 0,
"Open_Play" : 2,
"Penalty" : 1,
"Set_Piece" : 2,
"Own_goal" : 0
},
"Watford" :
{
"Counter_Attack" : 0,
"Open_Play" : 2,
"Penalty" : 0,
"Set_Piece" : 0,
"Own_goal" : 0
},
"West_Ham" :
{
"Counter_Attack" : 0,
"Open_Play" : 2,
"Penalty" : 0,
"Set_Piece" : 1,
"Own_goal" : 0
},
"Bournemouth" :
{
"Counter_Attack" : 0,
"Open_Play" : 2,
"Penalty" : 0,
"Set_Piece" : 0,
"Own_goal" : 0
},
"Manchester_City" :
{
"Counter_Attack" : 0,
"Open_Play" : 2,
"Penalty" : 1,
"Set_Piece" : 1,
"Own_goal" : 1
},
"Southampton" :
{
"Counter_Attack" : 0,
"Open_Play" : 1,
"Penalty" : 0,
"Set_Piece" : 1,
"Own_goal" : 0
},
"Middlesbrough" :
{
"Counter_Attack" : 0,
"Open_Play" : 1,
"Penalty" : 0,
"Set_Piece" : 1,
"Own_goal" : 0
},
"Leicester" :
{
"Counter_Attack" : 0,
"Open_Play" : 1,
"Penalty" : 0,
"Set_Piece" : 1,
"Own_goal" : 0
},
"Swansea" :
{
"Counter_Attack" : 0,
"Open_Play" : 1,
"Penalty" : 1,
"Set_Piece" : 0,
"Own_goal" : 0
},
"Sunderland" :
{
"Counter_Attack" : 0,
"Open_Play" : 1,
"Penalty" : 0,
"Set_Piece" : 0,
"Own_goal" : 0
},
"Tottenham" :
{
"Counter_Attack" : 0,
"Open_Play" : 1,
"Penalty" : 0,
"Set_Piece" : 1,
"Own_goal" : 0
},
"Crystal_Palace" :
{
"Counter_Attack" : 0,
"Open_Play" : 1,
"Penalty" : 0,
"Set_Piece" : 0,
"Own_goal" : 0
},
"Manchester_United" :
{
"Counter_Attack" : 0,
"Open_Play" : 1,
"Penalty" : 1,
"Set_Piece" : 1,
"Own_goal" : 0
},
"Hull" :
{
"Counter_Attack" : 0,
"Open_Play" :1,
"Penalty" : 0,
"Set_Piece" : 1,
"Own_goal" : 0
},
"West_Bromwich_Albion" :
{
"Counter_Attack" : 0,
"Open_Play" : 0,
"Penalty" : 0,
"Set_Piece" : 1,
"Own_goal" : 0
},
"Stoke" :
{
"Counter_Attack" : 0,
"Open_Play" : 0,
"Penalty" : 1,
"Set_Piece" : 0,
"Own_goal" : 0
},
"Everton" :
{
"Counter_Attack" : 0,
"Open_Play" : 0,
"Penalty" : 0,
"Set_Piece" : 1,
"Own_goal" : 1
}
},
"Away" :
{
"Chelsea" :
{
"Counter_Attack" : 1,
"Open_Play" : 3,
"Penalty" : 0,
"Set_Piece" : 0,
"Own_goal" : 0
},
"Liverpool" :
{
"Counter_Attack" : 0,
"Open_Play" : 3,
"Penalty" : 0,
"Set_Piece" : 1,
"Own_goal" : 1
},
"Burnley" :
{
"Counter_Attack" : 0,
"Open_Play" : 0,
"Penalty" : 0,
"Set_Piece" : 0,
"Own_goal" : 0
},
"Arsenal" :
{
"Counter_Attack" : 0,
"Open_Play" : 2,
"Penalty" : 1,
"Set_Piece" : 0,
"Own_goal" : 0
},
"Watford" :
{
"Counter_Attack" : 0,
"Open_Play" : 5,
"Penalty" : 0,
"Set_Piece" : 0,
"Own_goal" : 0
},
"West_Ham" :
{
"Counter_Attack" : 0,
"Open_Play" : 1,
"Penalty" : 0,
"Set_Piece" : 1,
"Own_goal" : 0
},
"Bournemouth" :
{
"Counter_Attack" : 0,
"Open_Play" : 0,
"Penalty" : 0,
"Set_Piece" : 1,
"Own_goal" : 0
},
"Manchester_City" :
{
"Counter_Attack" : 0,
"Open_Play" : 4,
"Penalty" : 1,
"Set_Piece" : 1,
"Own_goal" : 1
},
"Southampton" :
{
"Counter_Attack" : 0,
"Open_Play" : 0,
"Penalty" : 0,
"Set_Piece" : 0,
"Own_goal" : 1
},
"Middlesbrough" :
{
"Counter_Attack" : 0,
"Open_Play" : 2,
"Penalty" : 0,
"Set_Piece" : 0,
"Own_goal" : 0
},
"Leicester" :
{
"Counter_Attack" : 0,
"Open_Play" : 1,
"Penalty" : 1,
"Set_Piece" : 0,
"Own_goal" : 0
},
"Swansea" :
{
"Counter_Attack" : 0,
"Open_Play" : 2,
"Penalty" : 0,
"Set_Piece" : 0,
"Own_goal" : 0
},
"Sunderland" :
{
"Counter_Attack" : 0,
"Open_Play" : 1,
"Penalty" : 1,
"Set_Piece" : 0,
"Own_goal" : 0
},
"Tottenham" :
{
"Counter_Attack" : 1,
"Open_Play" : 4,
"Penalty" : 0,
"Set_Piece" : 1,
"Own_goal" : 0
},
"Crystal_Palace" :
{
"Counter_Attack" : 0,
"Open_Play" : 2,
"Penalty" : 0,
"Set_Piece" : 0,
"Own_goal" : 0
},
"Manchester_United" :
{
"Counter_Attack" : 0,
"Open_Play" : 4,
"Penalty" : 0,
"Set_Piece" : 0,
"Own_goal" : 0
},
"Hull" :
{
"Counter_Attack" : 0,
"Open_Play" :1,
"Penalty" : 0,
"Set_Piece" : 2,
"Own_goal" : 0
},
"West_Bromwich_Albion" :
{
"Counter_Attack" : 0,
"Open_Play" : 0,
"Penalty" : 0,
"Set_Piece" : 1,
"Own_goal" : 0
},
"Stoke" :
{
"Counter_Attack" : 0,
"Open_Play" : 0,
"Penalty" : 0,
"Set_Piece" : 1,
"Own_goal" : 0
},
"Everton" :
{
"Counter_Attack" : 0,
"Open_Play" : 4,
"Penalty" : 0,
"Set_Piece" : 1,
"Own_goal" : 0
}
}
},
"Summary" : {
"Arsenal" : 7.02,
"Bournemouth" : 6.67,
"Burnley" : 6.71,
"Chelsea" : 6.92,
"Crystal_Palace" : 6.88,
"Everton" : 7.12,
"Hull" : 7.04,
"Leicester" : 6.6,
"Liverpool" : 6.87,
"Manchester_City" : 7.06,
"Manchester_United" : 7.043,
"Middlesbrough" : 6.82,
"Southampton" : 6.57,
"Stoke" : 6.55,
"Sunderland" : 6.52,
"Swansea" : 6.83,
"Tottenham" : 7.01,
"Watford" : 6.7,
"West_Bromwich_Albion" : 6.73,
"West_Ham" : 6.74
},
"Shots" :
{
"Arsenal" :
{
"Total" : 13.0,
"OffTarget" : 5.0,
"OnTarget" : 3.5
},
"Bournemouth" :
{
"Total" : 10.5,
"OffTarget" : 3.5,
"OnTarget" : 4.0
},
"Burnley" :
{
"Total" : 8.7,
"OffTarget" : 4.0,
"OnTarget" : 2.3
},
"Chelsea" :
{
"Total" : 19.0,
"OffTarget" : 6.5,
"OnTarget" : 8.0
},
"Crystal_Palace" :
{
"Total" : 19.0,
"OffTarget" : 9.5,
"OnTarget" : 4.5
},
"Everton" :
{
"Total" : 16.5,
"OffTarget" : 5.5,
"OnTarget" : 7.5
},
"Hull" :
{
"Total" : 11.0,
"OffTarget" : 5.5,
"OnTarget" : 3.5
},
"Leicester" :
{
"Total" : 10.5,
"OffTarget" : 3.5,
"OnTarget" : 3.5
},
"Liverpool" :
{
"Total" : 17.0,
"OffTarget" : 2.0,
"OnTarget" : 11.0
},
"Manchester_City" :
{
"Total" : 19.0,
"OffTarget" : 9.0,
"OnTarget" : 4.5
},
"Manchester_United" :
{
"Total" : 13.0,
"OffTarget" : 6.0,
"OnTarget" : 4
},
"Middlesbrough" :
{
"Total" : 12.0,
"OffTarget" : 5.5,
"OnTarget" : 3.0
},
"Southampton" :
{
"Total" : 20.0,
"OffTarget" : 7.5,
"OnTarget" : 6.5
},
"Stoke" :
{
"Total" : 12.0,
"OffTarget" : 5.0,
"OnTarget" : 2.5
},
"Sunderland" :
{
"Total" : 14.5,
"OffTarget" : 3.5,
"OnTarget" : 3.5
},
"Swansea" :
{
"Total" : 14.5,
"OffTarget" : 7.5,
"OnTarget" : 2.5
},
"Tottenham" :
{
"Total" : 15.5,
"OffTarget" : 7.0,
"OnTarget" : 4.5
},
"Watford" :
{
"Total" : 10.0,
"OffTarget" : 4.0,
"OnTarget" : 4.0
},
"West_Bromwich_Albion" :
{
"Total" : 12.0,
"OffTarget" : 5.5,
"OnTarget" : 3.0
},
"West_Ham" :
{
"Total" : 17.5,
"OffTarget" : 10.0,
"OnTarget" : 3.0
}
},
"Passes" :
{
"Home" :
{
"Arsenal" :
{
"Cross" : 24,
"ThroughBall" : 4,
"LongBall" : 51,
"ShortPass" : 489
},
"Bournemouth" :
{
"Cross" : 26,
"ThroughBall" : 1,
"LongBall" : 65,
"ShortPass" : 420
},
"Burnley" :
{
"Cross" : 15,
"ThroughBall" : 0,
"LongBall" : 77,
"ShortPass" : 245
},
"Chelsea" :
{
"Cross" : 23,
"ThroughBall" : 2,
"LongBall" : 70,
"ShortPass" : 527
},
"Crystal_Palace" :
{
"Cross" : 36,
"ThroughBall" : 0,
"LongBall" : 82,
"ShortPass" : 356
},
"Everton" :
{
"Cross" : 16,
"ThroughBall" : 1,
"LongBall" : 75,
"ShortPass" : 355
},
"Hull" :
{
"Cross" : 11,
"ThroughBall" : 2,
"LongBall" : 86,
"ShortPass" : 336
},
"Leicester" :
{
"Cross" : 17,
"ThroughBall" : 1,
"LongBall" : 73,
"ShortPass" : 315
},
"Liverpool" :
{
"Cross" : 7,
"ThroughBall" : 3,
"LongBall" : 75,
"ShortPass" : 534
},
"Manchester_City" :
{
"Cross" : 20,
"ThroughBall" : 4,
"LongBall" : 56,
"ShortPass" : 579
},
"Manchester_United" :
{
"Cross" : 22,
"ThroughBall" : 1,
"LongBall" : 57,
"ShortPass" : 341
},
"Middlesbrough" :
{
"Cross" : 28,
"ThroughBall" : 0,
"LongBall" : 74,
"ShortPass" : 368
},
"Southampton" :
{
"Cross" : 26,
"ThroughBall" : 3,
"LongBall" : 51,
"ShortPass" : 486
},
"Stoke" :
{
"Cross" : 20,
"ThroughBall" : 1,
"LongBall" : 67,
"ShortPass" : 283
},
"Sunderland" :
{
"Cross" : 17,
"ThroughBall" : 2,
"LongBall" : 54,
"ShortPass" : 291
},
"Swansea" :
{
"Cross" : 27,
"ThroughBall" : 0,
"LongBall" : 51,
"ShortPass" : 437
},
"Tottenham" :
{
"Cross" : 20,
"ThroughBall" : 2,
"LongBall" : 76,
"ShortPass" : 361
},
"Watford" :
{
"Cross" : 20,
"ThroughBall" : 1,
"LongBall" : 68,
"ShortPass" : 305
},
"West_Bromwich_Albion" :
{
"Cross" : 20,
"ThroughBall" : 0,
"LongBall" : 67,
"ShortPass" : 253
},
"West_Ham" :
{
"Cross" : 24,
"ThroughBall" : 1,
"LongBall" : 58,
"ShortPass" : 345
}
},
"Away" :
{
"Arsenal" :
{
"Cross" : 19,
"ThroughBall" : 5,
"LongBall" : 55,
"ShortPass" : 474
},
"Bournemouth" :
{
"Cross" : 14,
"ThroughBall" : 2,
"LongBall" : 76,
"ShortPass" : 296
},
"Burnley" :
{
"Cross" : 20,
"ThroughBall" : 0,
"LongBall" : 54,
"ShortPass" : 365
},
"Chelsea" :
{
"Cross" : 24,
"ThroughBall" : 2,
"LongBall" : 55,
"ShortPass" : 474
},
"Crystal_Palace" :
{
"Cross" : 24,
"ThroughBall" : 1,
"LongBall" : 73,
"ShortPass" : 287
},
"Everton" :
{
"Cross" : 19,
"ThroughBall" : 2,
"LongBall" : 79,
"ShortPass" : 500
},
"Hull" :
{
"Cross" : 16,
"ThroughBall" : 3,
"LongBall" : 84,
"ShortPass" : 460
},
"Leicester" :
{
"Cross" : 17,
"ThroughBall" : 1,
"LongBall" : 67,
"ShortPass" : 339
},
"Liverpool" :
{
"Cross" : 17,
"ThroughBall" : 2,
"LongBall" : 66,
"ShortPass" : 528
},
"Manchester_City" :
{
"Cross" : 15,
"ThroughBall" : 5,
"LongBall" : 63,
"ShortPass" : 482
},
"Manchester_United" :
{
"Cross" : 24,
"ThroughBall" : 1,
"LongBall" : 61,
"ShortPass" : 531
},
"Middlesbrough" :
{
"Cross" : 13,
"ThroughBall" : 3,
"LongBall" : 90,
"ShortPass" : 407
},
"Southampton" :
{
"Cross" : 20,
"ThroughBall" : 1,
"LongBall" : 72,
"ShortPass" : 427
},
"Stoke" :
{
"Cross" : 20,
"ThroughBall" : 1,
"LongBall" : 56,
"ShortPass" : 357
},
"Sunderland" :
{
"Cross" : 18,
"ThroughBall" : 2,
"LongBall" : 62,
"ShortPass" : 171
},
"Swansea" :
{
"Cross" : 26,
"ThroughBall" : 0,
"LongBall" : 67,
"ShortPass" : 314
},
"Tottenham" :
{
"Cross" : 20,
"ThroughBall" : 0,
"LongBall" : 78,
"ShortPass" : 423
},
"Watford" :
{
"Cross" : 14,
"ThroughBall" : 1,
"LongBall" : 72,
"ShortPass" : 258
},
"West_Bromwich_Albion" :
{
"Cross" : 19,
"ThroughBall" : 1,
"LongBall" : 81,
"ShortPass" : 182
},
"West_Ham" :
{
"Cross" : 13,
"ThroughBall" : 1,
"LongBall" : 83,
"ShortPass" : 235
}
}
},
"Recent" :
{
"Manchester_City" :
{
"Game1" : 1,
"Game2" : 1,
"Game3" : 1,
"Game4" : 1,
"Game5" : 1
},
"Everton" :
{
"Game1" : 0,
"Game2" : 1,
"Game3" : 1,
"Game4" : 1,
"Game5" : 1
},
"Tottenham" :
{
"Game1" : 0,
"Game2" : 1,
"Game3" : 0,
"Game4" : 1,
"Game5" : 1
},
"Arsenal" :
{
"Game1" : -1,
"Game2" : 0,
"Game3" : 1,
"Game4" : 1,
"Game5" : 1
},
"Chelsea" :
{
"Game1" : 1,
"Game2" : 1,
"Game3" : 1,
"Game4" : 0,
"Game5" : 1
},
"Liverpool" :
{
"Game1" : 1,
"Game2" : -1,
"Game3" : 0,
"Game4" : 1,
"Game5" : 1
},
"Manchester_United" :
{
"Game1" : 1,
"Game2" : 1,
"Game3" : 1,
"Game4" : -1,
"Game5" : -1
},
"Crystal_Palace" :
{
"Game1" : -1,
"Game2" : -1,
"Game3" : 0,
"Game4" : 1,
"Game5" : 1
},
"Watford" :
{
"Game1" : 0,
"Game2" : -1,
"Game3" : -1,
"Game4" : 1,
"Game5" : 1
},
"West_Bromwich_Albion" :
{
"Game1" : 1,
"Game2" : -1,
"Game3" : 0,
"Game4" : -1,
"Game5" : 1
},
"Leicester" :
{
"Game1" : -1,
"Game2" : 0,
"Game3" : 1,
"Game4" : -1,
"Game5" : 1
},
"Hull" :
{
"Game1" : 1,
"Game2" : 1,
"Game3" : -1,
"Game4" : 0,
"Game5" : -1
},
"Middlesbrough" :
{
"Game1" : 0,
"Game2" : 1,
"Game3" : 0,
"Game4" : -1,
"Game5" : -1
},
"Southampton" :
{
"Game1" : 0,
"Game2" : -1,
"Game3" : 0,
"Game4" : -1,
"Game5" : 1
},
"Swansea" :
{
"Game1" : 1,
"Game2" : -1,
"Game3" : -1,
"Game4" : 0,
"Game5" : -1
},
"Burnley" :
{
"Game1" : -1,
"Game2" : 1,
"Game3" : -1,
"Game4" : 0,
"Game5" : -1
},
"Bournemouth" :
{
"Game1" : -1,
"Game2" : -1,
"Game3" : 0,
"Game4" : 1,
"Game5" : -1
},
"West_Ham" :
{
"Game1" : -1,
"Game2" : 1,
"Game3" : -1,
"Game4" : -1,
"Game5" : -1
},
"Sunderland" :
{
"Game1" : -1,
"Game2" : -1,
"Game3" : 0,
"Game4" : -1,
"Game5" : -1
},
"Stoke" :
{
"Game1" : 0,
"Game2" : -1,
"Game3" : -1,
"Game4" : -1,
"Game5" : -1
}
},
"Head2Head" :
{
}
}
}
这是一个由英超联赛球队数据组成的数据库。现在,由于Firebase使用Jackson来反序列化JSON,我在这里有一个很大的问题,我需要创建很多类来访问这些数据,所以我想的一个解决方案是在一个俱乐部名称下尽可能多的值,这里重复一遍。这样可以最大限度地减少冗余类的使用,但是我想知道是否可以通过Firebase进行任何调整以轻松访问这些值。
但还有另一个问题,即我还需要存储head2head
值,即当两支队伍面对面时的统计数据,因为有20支队伍,它将有380场比赛及其相关联统计。如果我这样做,那就是:
"Head2Head" :
{
"M1X" :
{
"Team1": 290,
"Team2": 180,
"Draw" : 30
}
}
哪个会强制创建大约380个Java类。我错过了任何以极少的方式减少任务的常见调整。我可以通过Firebase做些什么来解决这样的问题吗?请帮助。
答案 0 :(得分:1)
总的来说,你需要移动"键"进入对象,给每个班级一个名字"领域。
第1课:A Team
。
"Chelsea" :
{
"Counter_Attack" : 0,
"Open_Play" : 4,
"Penalty" : 1,
"Set_Piece" : 0,
"Own_goal" : 0
},
"Liverpool" :
{
"Counter_Attack" : 0,
"Open_Play" : 4,
"Penalty" : 0,
"Set_Piece" : 0,
"Own_goal" : 0
},
为"home"
和"away"
"home": [
{ "Name": "Chelsea", "Open_Play": 4, ...},
{ "Name": "Liverpool", "Open_Play": 4, ...},
...
]
第2课:Summary
看起来不错。
第3课:Shot
"Arsenal" :
{
"Total" : 13.0,
"OffTarget" : 5.0,
"OnTarget" : 3.5
},
"Bournemouth" :
{
"Total" : 10.5,
"OffTarget" : 3.5,
"OnTarget" : 4.0
},
成为这个
"shots": [
{"Name": "Arsenal", "Total": 13.0, ...},
{"Name": "Bournemouth", "Total": 10.5, ...},
...
]
第4课:Passes
- 同样的想法
第5课:Recent
"Manchester_City" :
{
"Game1" : 1,
"Game2" : 1,
"Game3" : 1,
"Game4" : 1,
"Game5" : 1
},
"Everton" :
{
"Game1" : 0,
"Game2" : 1,
"Game3" : 1,
"Game4" : 1,
"Game5" : 1
},
游戏可能更好地表现为列表
"recents": [
{"Name": "Manchester_City", "games": [1, 1, 1, 1, 1]},
{"Name": "Everton", "games": [0, 1, 1, 1, 1]},
...
]