如何为可以是对象或字符串的属性生成GSONFormat? [英] How to generate GSONFormat for a property that can either be an object or string?

查看:114
本文介绍了如何为可以是对象或字符串的属性生成GSONFormat?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用GSON来解析Volley请求的响应,并且当响应具有可以是字符串,对象或数组的属性时,就陷入了创建GSON格式的困扰.例如 content

I'm using GSON for parsing response from a Volley request and got stuck in creating a GSON format when the response has a property that can either be a string or an object or an array perhaps... e.g content

{
      "data": {
        "date_updated": "2016-12-21T03:55:29.955Z",
        "date_created": "2016-12-21T03:55:29.955Z",
        "content": "String here",
        "content": {
            "longitude": "",
            "latitude": ""
        },
        "status": "PROC",
        "_id": "5859fd31a93c7235575d62db"
      }
}

我当前创建GSON模型的过程是:

My current process in creating a GSON model is:

  1. 创建一个Java类
  2. 右键单击并选择生成">"GSONFormat"
  3. 粘贴要尝试转换的对象,然后在Volley中使用它. 我尝试了上述对象,但没有进行.我认为是因为属性名称相同.
  1. Create a java class
  2. Right click and select Generate > GSONFormat
  3. Paste the object I'm trying to convert then use it in Volley. I tried the above object but it doesn't proceed. I think it's because of same property name.

感谢您的建议.

推荐答案

您可以使用GsonFormat,如下所示: https://github.com/zzz40500/GsonFormat

You can use GsonFormat, you can look this: https://github.com/zzz40500/GsonFormat

这篇关于如何为可以是对象或字符串的属性生成GSONFormat?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆