我刚开始使用 Google Cloud Endpoints,我用 Python 构建了一个 API,甚至还可以在 Android Studio/Gradle 环境中使用生成的源代码。
我面临一个问题,即每当来自 Cloud Endpoints 的响应包含 DateTime 对象时,就会引发 NumberFormatException。
08-05 13:27:28.143 32116-32141/com.dgt.ds E/AndroidRuntime: FATAL EXCEPTION: AsyncTask #1
java.lang.RuntimeException: An error occured while executing doInBackground()
at android.os.AsyncTask$3.done(AsyncTask.java:299)
at java.util.concurrent.FutureTask$Sync.innerSetException(FutureTask.java:273)
at java.util.concurrent.FutureTask.setException(FutureTask.java:124)
at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:307)
at java.util.concurrent.FutureTask.run(FutureTask.java:137)
at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:230)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1076)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:569)
at java.lang.Thread.run(Thread.java:856)
Caused by: java.lang.IllegalArgumentException: [key created_at, field private com.google.api.client.util.DateTime com.google.api.services.dsApi.model.ServicesDResponse.createdAt]
at com.google.api.client.json.JsonParser.parseValue(JsonParser.java:797)
at com.google.api.client.json.JsonParser.parse(JsonParser.java:438)
at com.google.api.client.json.JsonParser.parseValue(JsonParser.java:745)
at com.google.api.client.json.JsonParser.parse(JsonParser.java:358)
at com.google.api.client.json.JsonParser.parse(JsonParser.java:331)
at com.google.api.client.json.JsonObjectParser.parseAndClose(JsonObjectParser.java:87)
at com.google.api.client.json.JsonObjectParser.parseAndClose(JsonObjectParser.java:81)
at com.google.api.client.http.HttpResponse.parseAs(HttpResponse.java:459)
at com.google.api.client.googleapis.services.AbstractGoogleClientRequest.execute(AbstractGoogleClientRequest.java:460)
at com.dgt.ds.MainActivity$1.doInBackground(MainActivity.java:70)
at com.dgt.ds.MainActivity$1.doInBackground(MainActivity.java:58)
at android.os.AsyncTask$2.call(AsyncTask.java:287)
at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:305)
... 5 more
Caused by: java.lang.NumberFormatException: Invalid date/time format: 2013-08-05T10:27:27.449810
at com.google.api.client.util.DateTime.parseRfc3339(DateTime.java:301)
at com.google.api.client.util.Data.parsePrimitiveValue(Data.java:435)
at com.google.api.client.json.JsonParser.parseValue(JsonParser.java:795)
... 17 more
这是 Python 中的消息对象(我正在使用message_types.DateTimeField
):
class DResponse(messages.Message):
id = messages.StringField(1)
created_at = message_types.DateTimeField(2)
author = messages.StringField(3)
description = messages.StringField(4, required=True)
我怎样才能解决这个问题 ?