我在json文件中收集了推文。我想对它们进行操作,例如根据每个数据条目的时间和坐标对推文进行分组。目前对于对象坐标我在List数据类型中有它们。与时间和日期相似。所以我已经成功地解析了它们,但是我很难对它们进行操作,尤其是数据时间和坐标。
最终目标是让我可以更轻松地对它们进行操作。
如何将List数据类型转换为双重存储?
我不确定我应该将什么数据类型用于时间和日期
这是json元素的一个例子
{"text": "Flood/Storm/Tree Down. Northern Beaches (King Rd, Ingleside, NSW 2101) at 6 Mar 2017 21:38,
"user": {"id": "4721717942", "name": "NSW Fire Updates"}, "lang": "en",
"coordinates": { "coordinates": [151.264811, -33.6848] , "type":"Point"}, "created_at": "Mon Mar 06 10:44:31 +0000 2017"}
这是我制作的坐标类
public class Coordinates {
private String type;
private List<String> coordinates;
public String getType (){
return type;
}
public void setType (String type){
this.type = type;
}
public List<String> getCoordinates(){
return coordinates;
}
public void setCoordinates (List<String> coordinates){
this.coordinates = coordinates;
}
@Override
public String toString(){
return "[type = "+type+", coordinates = "+coordinates+"]";
}
}
这是包含时间和日期的课程
@JsonIgnoreProperties(ignoreUnknown = true)
public class Tweet {
private String text;
private String created_at;
private User user;
private Coordinates coordinates;
public Tweet(){
}
public String getText()
{
return text;
}
public void setText(String text)
{
this.text = text;
}
public String getCreated_at()
{
return created_at;
}
public void setCreated_at(String created_at)
{
this.created_at = created_at;
}
public User getUser()
{
return user;
}
public void setUser(User user)
{
this.user = user;
}
public Coordinates getCoordinates()
{
return coordinates;
}
public void setCoordinates(Coordinates coordinates)
{
this.coordinates = coordinates;
}
@Override
public String toString()
{
return "[text = "+text+", created_at = "+created_at+", user = "+user+", coordinates = "+coordinates+"]";
}
}
答案 0 :(得分:1)
尝试了解java 8流图和过滤操作,您可以在一行代码中完成您的工作。 https://docs.oracle.com/javase/8/docs/api/java/util/stream/package-summary.html或者如果您不能使用java 8,请从此帖子中尝试此示例Sorting Java objects using multiple keys