1

我正在使用 rabl 以 json 格式显示我的数据库中的数据,以将其解析为 android...我的 json 看起来像这样:

[
   {
      "bank":{
         "central_office_address":"ololo",
         "license":"12312312",
         "location_id":3,
         "name":"Pbank",
         "tax_number":"12312312",
         "year_of_foundation":1987
      }
   },
   {
      "bank":{
         "central_office_address":"sdfsdf sdf",
         "license":"321312",
         "location_id":3,
         "name":"Bbank",
         "tax_number":"321321",
         "year_of_foundation":1999
      }
   }
]

我需要我的 json 格式如下:

{
    "contacts": [
        {
                "id": "c200",
                "name": "Ravi Tamada",
                "email": "ravi@gmail.com",
                "address": "xx-xx-xxxx,x - street, x - country",
                "gender" : "male",
                "phone": {
                    "mobile": "+91 0000000000",
                    "home": "00 000000",
                    "office": "00 000000"
                }
        },
        {
                "id": "c201",
                "name": "Johnny Depp",
                "email": "johnny_depp@gmail.com",
                "address": "xx-xx-xxxx,x - street, x - country",
                "gender" : "male",
                "phone": {
                    "mobile": "+91 0000000000",
                    "home": "00 000000",
                    "office": "00 000000"
                }
        }
    ]
}

这些数据通常在java中解析......

我的观点:

object @banks

attributes :central_office_address, :license, :location_id, :name, :tax_number, :year_of_foundation

如何更改其输出以匹配第二个示例?

4

1 回答 1

1

我已经这样做了:

collection @banks, :root => "bank", :object_root => false
attributes :central_office_address, :license, :location_id, :name, :tax_number, :year_of_foundation

也许这是个坏主意?

于 2013-04-06T18:24:47.440 回答