【发布时间】:2019-12-04 06:35:54
【问题描述】:
我遇到了与在 Android 应用中解析 Firestore 时间戳相关的问题。
总结
在我的 Firebase Firestore 中,我有一组 cmets。每条评论都是这样的
(时间是时间戳类型)
我已经使用 Cloud Functions 构建了 REST API。 cmets 端点有一个 GET 方法。共享整个代码没有意义,重要的事实是,来自该端点的响应看起来像这样
如您所见,响应看起来不错,一切正常。
问题
现在,我有一个使用 Retrofit 与 API 通信的 Android 应用。它向上述端点发出请求并获得响应(响应为<List<CommentResponse>>)。
import com.google.firebase.Timestamp
data class CommentResponse(
val placeId: String,
val userUid: String,
val userDisplayName: String,
val userPhotoUrl: String,
val time: Timestamp,
val text: String
)
但是当我做Log.d(response.body)时,我得到(我删掉了不重要的数据)
[CommentResponse(placeId=opactwo, userUid=e09E...82, userDisplayName=Bartek Pacia, userPhotoUrl=https: .../photo.jpg, time=Timestamp(seconds=0, nanoseconds=0), text=This place is very beautiful :D)]
时间戳消失了。它不为空,但它指向时代的开始(1.1.1970)。这只是 0 秒,0 纳秒。我不使用任何自定义转换器或其他任何东西,只是“初级改造”。
嗯,就是这样。 我不知道为什么时间戳变为 0,0。
如果有人可以帮助我,我将不胜感激。 提前谢谢你。
【问题讨论】:
-
time是 JsonObject,其中包含seconds和nanoseconds键
标签: android firebase google-cloud-firestore google-cloud-functions retrofit