简体   繁体   English

Java JSON POJO映射

[英]Java JSON POJO mapping

I am using the met office for weather data for which they have 171 weather sites in the UK. 我正在使用会议办公室获取天气数据,他们在英国拥有171个气象站。 This is going into a mongo database. 这将进入mongo数据库。 As the weather sites differ in sensors and capability so then does the data you get back from it. 由于气象站的传感器和功能各不相同,因此您从中获取的数据也会随之变化。 An example of two sites is shown below. 下面显示了两个站点的示例。

My question is how do you POJO such a JSON structure if data can change as it does.What is a best approach for such an instance. 我的问题是,如果数据可以更改,您如何POJO这样的JSON结构?这种实例的最佳方法是什么?

  { "_id": ObjectId("54ca68c8ccf2562b665edb53"), "dataDate": "2015-01-29T16:00:00Z", "i": "3609", "lat": "51.565", "lon": "-3.981", "name": "MUMBLES HEAD", "country": "WALES", "continent": "EUROPE", "elevation": "32.0", "Period": { "type": "Day", "value": "2015-01-29Z", "Rep": { "D": "W", "G": "37", "H": "73.8", "P": "996", "S": "13", "T": "4.9", "Pt": "F", "Dp": "0.6", "MinSinceMidnight": "240" } } } 

Unfortunately there are other sites with less sensors etc so the data can look like this: 不幸的是,其他站点的传感器等也较少,因此数据如下所示:

  { "_id": ObjectId("5576c770e4b046add9b0126f"), "dataDate": "2015-06-09T10:00:00Z", "i": "99159", "lat": "50.61359", "lon": "-1.95875", "name": "SWANAGE", "country": "ENGLAND", "continent": "EUROPE", "elevation": "10.0", "Period": { "type": "Day", "value": "2015-06-09Z", "Rep": { "H": "59.7", "T": "13.6", "Dp": "5.9", "MinSinceMidnight": "600" } } } 

使用org.json java库中的JSONObject类。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM