【发布时间】:2017-09-20 21:41:45
【问题描述】:
我有这种 json,它有这种奇怪格式的 news_date 对象
"news_date":"\/Date(1452412800000)\/"
下面是我的完整 json
[{"ID":1,"title":"Add News RSS and WordPress feeds into the ultimate Android News app","details":"If you ve ever wanted to create a specialized News app that takes WordPress feeds News feeds and ","photo_name":"hhh.jpg","news_date":"\/Date(1451721600000)\/","category":"News"},{"ID":2,"title":"Groupon","details":"Groupon is one of the best and most popular coupon apps available on Android","photo_name":"kkk.jpg","news_date":"\/Date(1452412800000)\/","category":"News"},{"ID":3,"title":"Kodi","details":"If you ve ever wanted to create a specialized News app that takes WordPress feeds News feeds and ","photo_name":"lll.jpg","news_date":"\/Date(1452672000000)\/","category":"News"},{"ID":48,"title":"Add News RSS and WordPress feeds into the ultimate Android News app","details":"If you ve ever wanted to create a specialized News app that takes WordPress feeds News feeds and ","photo_name":"nnn.jpg","news_date":"\/Date(1483430400000)\/","category":"News"},{"ID":49,"title":"Groupon","details":"Groupon is one of the best and most popular coupon apps available on Android","photo_name":"pp.jpg","news_date":"\/Date(1491721200000)\/","category":"News"},{"ID":50,"title":"Add News RSS and WordPress feeds into the ultimate Android News app","details":"If you ve ever wanted to create a specialized News app that takes WordPress feeds News feeds and ","photo_name":"sss.jpg","news_date":"\/Date(1484121600000)\/","category":"News"},{"ID":51,"title":"Groupon","details":"Groupon is one of the best and most popular coupon apps available on Android","photo_name":"vvv.jpg","news_date":"\/Date(1491721200000)\/","category":"News"}]
我能够检索除news_date 之外的所有其他json objects,因为在我的Mysql table 中,它的数据类型 是date,这就是它表现得那样的原因,我怎样才能检索到@987654330 @在date format.
下面是我的模型类
package model;
/**
* Created by Admin on 1/28/2017.
*/
public class NewsObject {
private String title;
private String details;
private String photo_name;
private String news_date;
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public String getDetails() {
return details;
}
public void setDetails(String details) {
this.details = details;
}
public String getPhoto_name() {
return photo_name;
}
public void setPhoto_name(String photo_name) {
this.photo_name = photo_name;
}
public String getNews_date() {
return news_date;
}
public void setNews_date(String news_date) {
this.news_date = news_date;
}
}
【问题讨论】:
-
更改日期响应,然后使用simpledateformat格式化或解析日期
-
@AnandSavjani,请告诉我如何,假设我有一个字符串
String d = sr.getNews_Date();的初学者如何使用 SimpleDateFomat 更改该字符串名称 -
从后端将
Date(1452412800000)替换为1452412800000 -
参考这个将毫秒转换为时间stackoverflow.com/questions/17624335/…