2013-04-06 68 views
1

我从我的分贝JSON格式使用Rabl的解析在Android系统显示数据... 的json看起来像这样:Rails的Rabl的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": "[email protected]", 
       "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": "[email protected]", 
       "address": "xx-xx-xxxx,x - street, x - country", 
       "gender" : "male", 
       "phone": { 
        "mobile": "+91 0000000000", 
        "home": "00 000000", 
        "office": "00 000000" 
       } 
     } 
    ] 
} 

这样的数据是用Java通常解析....

我Rabl的视图:

object @banks 

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

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

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

也许是坏主意:

回答

1

我在这样的方式进行?

+0

从回卷编辑评论:它必须是“银行”,而不是“银行”,以符合他所需的格式。 – 2013-06-29 04:15:37