MS WCF 兼容形式的日期字段的 gson 序列化
我通过 POST 方法访问 Web 服务。我需要向服务器发送一个 json 序列化对象。在我的 Android 类中,我有一些字符串字段和一个日期字段。这个日期字段像这样序列化:
.... TouchDateTime":"Oct 6, 2010 5:55:29 PM"}"
但为了与网络服务兼容,我需要这样:
"TouchDateTime":"\/Date(928138800000+0300)\/"
我在这里找到了一篇关于反序列化的有趣文章:http://benjii.me/2010/04/deserializing-json-in-android-using-gson/ 我想我需要做这样的事情。你能帮我一把吗?
I access a web service in a POST method. I need to send to the server a json serialized object. In my Android class I have some string fields and a Date field. This Date field gets serialized like this:
.... TouchDateTime":"Oct 6, 2010 5:55:29 PM"}"
but to be compatible with the web service I need to have it like:
"TouchDateTime":"\/Date(928138800000+0300)\/"
I found an interesting article about Deserialization in here: http://benjii.me/2010/04/deserializing-json-in-android-using-gson/ I think I need to do something like this. Could you give me a helping hand ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果有人需要,我就是这样做的。
1. 创建一个新类 DateSerializer 并将其放入其中:
以下是我如何使用它:
In case anybody needs it, here is how I did it.
1. Create a new class DateSerializer and put in it:
And here is how I use it:
如果有人同时需要序列化和反序列化,我已经为它准备了一个GsonHelper:
如何将 .net DateTime 作为 json 字符串解析为 java 的 Date 对象
If someone needs both serialization and deserialization, I've prepared a GsonHelper for it:
How to parse .net DateTime received as json string into java's Date object