[英]Convert a java list of data into a JSON array of array
Good morning, everyone.大家,早安。 Hope you're well.
希望你一切都好。 Actually I'd like to convert a list with data into a JSON table of this form:
实际上,我想将带有数据的列表转换为这种形式的 JSON 表:
[[45.21406,5.74749,445,"2019-11-05T15:29:45Z"],
[45.21401,5.74752,470,"2019-11-05T15:29:46Z"],
[45.21397,5.74763,472,"2019-11-05T15:29:47Z"],
[45.21393,5.74789,471,"2019-11-05T15:29:48Z"],
[45.21389,5.74849,473,"2019-11-05T15:29:49Z"]
]
My code is the next:我的代码是下一个:
activity.longitude=result.getLastLocation().getLongitude();
activity.latitude=result.getLastLocation().getLatitude();
DateFormat formatter = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss");
activity.dateFormated= formatter.format(new Date());
activity.altitude=result.getLastLocation().getAltitude();
activity.data.add(activity.longitude);
activity.data.add(activity.latitude);
activity.data.add(activity.dateFormated);
activity.data.add(activity.altitude);
Thank you very much for your help.非常感谢您的帮助。
You need to use a JSON library to make this easy and correct.您需要使用 JSON 库来使这变得简单而正确。 This is a simple one to get started with.
这是一个简单的开始。
https://github.com/stleary/JSON-java https://github.com/stleary/JSON-java
so this can be done using a host of different libraries but one that could be particularly helpful is Gson .所以这可以使用许多不同的库来完成,但一个可能特别有用的是Gson 。 Unfortunately you have not posted your POJO that represented these values so it's difficult to help you further and give an example but this should help.
不幸的是,您尚未发布代表这些值的 POJO,因此很难进一步帮助您并举例说明,但这应该会有所帮助。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.