【问题标题】:How to generate PoJo class if we have the JSONobject and JSONarray in the API response?如果 API 响应中有 JSONobject 和 JSONarray,如何生成 PoJo 类?
【发布时间】:2016-12-15 07:44:34
【问题描述】:
{
    "CustId": "10705",
    "UserName": "3721",
    "Password": null,
    "AdminPassword": null,
    "CustName": "PB 65 V 3721",
    "CustType": "30",
    "CustKey": "980964ee-2abd-4352-9817-206d7ece8d04",
    "IsSubUser": true,
    "Announcement": "",
    "showIcons": "1111111111",
    "ResponseStatus": {
        "Status": true,
        "ErrorCode": null,
        "StackTrace": null,
        "Message": null,
        "Error": null
    }
}

【问题讨论】:

  • 使用谷歌!关于这个问题有数百个答案!尝试搜索 Gson。请下一次,在发布问题之前,请在网络上进行一些小研究!如果你有朝一日想成为一名开发人员,这是一项至关重要的技能!
  • 尝试使用 Jackson 或 GS​​ON 库将 JSON 转换为 java 对象。

标签: android json pojo


【解决方案1】:

访问here

  1. 将 JSON 粘贴到左侧。
  2. 然后选择 JSON 类型
  3. 注解风格:Gson
  4. getter/setter 点击预览/保存 Zip。

完成后,您必须进行一些编辑以维护嵌套类。

【讨论】:

    【解决方案2】:

    使用 json pojo 在线工具。我最常用的是这个。这是link

    只需在此处发布您的回复,它就会为您转换 pojo。然后您可以使用 gson 将 json 映射到您的 pojo。

    我希望这会对你有所帮助。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-05-12
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多