如何在Retrofit中映射此输出?

时间:2017-04-30 08:59:06

标签: android gson retrofit

我是Retrofit的新手,我从服务器上获得了以下JSON:

    {
     "2": {
        "entity_id": "2",
        "website_id": "1",
        "email": "ddd@gmail.xx",
        "group_id": "1",
        "created_at": "2013-08-05 13:13:29",
        "disable_auto_group_change": "0",
        "prefix": null,
        "firstname": "dennis",
        "middlename": null,
        "lastname": "Napf",
        "suffix": null,
        "taxvat": null,
        "created_in": "Admin"
     },
     "3": {
        "entity_id": "3",
        "website_id": "1",
        "email": "pit@gmail.xx",
        "group_id": "1",
        "created_at": "2013-08-14 17:48:28",
        "disable_auto_group_change": "0",
        "prefix": null,
        "firstname": "pit",
        "middlename": null,
        "lastname": "doe",
        "suffix": null,
        "taxvat": null,
        "created_in": "Admin"
     },
     "4": {
        "entity_id": "4",
        "website_id": "1",
        "email": "xxxx@ttt.com`enter code here`",
        "group_id": "1",
        "created_at": "2013-08-14 17:49:32",
        "disable_auto_group_change": "0",
        "prefix": null,
        "firstname": "qqqqqqqqqqqqqq",
        "middlename": null,
        "lastname": "wwwwwwwwwwwwwwwwwwww",
        "suffix": null,
        "taxvat": null,
        "created_in": "Admin"
      }
    }    

我不知道如何映射这个。缺少对象名称(此处为客户)。相反,我得到了客户的身份。在调试器中,我可以看到此结果是LinkedTreeMap

1 个答案:

答案 0 :(得分:0)

这似乎是一个糟糕的json,请按照以下方式进行更改

{
  "info": {
  [ 
 {
    "entity_id": "2",
    "website_id": "1",
    "email": "ddd@gmail.xx",
    "group_id": "1",
    "created_at": "2013-08-05 13:13:29",
    "disable_auto_group_change": "0",
    "prefix": null,
    "firstname": "dennis",
    "middlename": null,
    "lastname": "Napf",
    "suffix": null,
    "taxvat": null,
    "created_in": "Admin"
 },{
    "entity_id": "3",
    "website_id": "1",
    "email": "pit@gmail.xx",
    "group_id": "1",
    "created_at": "2013-08-14 17:48:28",
    "disable_auto_group_change": "0",
    "prefix": null,
    "firstname": "pit",
    "middlename": null,
    "lastname": "doe",
    "suffix": null,
    "taxvat": null,
    "created_in": "Admin"
 },{
    "entity_id": "4",
    "website_id": "1",
    "email": "xxxx@ttt.com`enter code here`",
    "group_id": "1",
    "created_at": "2013-08-14 17:49:32",
    "disable_auto_group_change": "0",
    "prefix": null,
    "firstname": "qqqqqqqqqqqqqq",
    "middlename": null,
    "lastname": "wwwwwwwwwwwwwwwwwwww",
    "suffix": null,
    "taxvat": null,
    "created_in": "Admin"
    }
   ]
  }
 }

关于解析使用此tutorial可能会帮助您