我正在使用 rabl 在 Sinatra 中构建和 API。所需的 JSON des 不接受某些节点中的标签使用此 Rabl 模板:
object @user
attributes :profile_photo => :profile_photo, :name => :first_name, :last_name => :last_name
child :addresses do
attributes :id
child :country do
attributes :name
end
end
我得到以下 JSON:
{
user: {
profile_photo: null,
first_name: "John",
last_name: "Doe",
addresses: [
{
address: {
id: 43,
country: {
name: "Iceland"
}
}
},
{
address: {
id: 44,
country: {
name: "Cambodia"
}
}
},
{
address: {
id: 45,
country: {
name: "North Korea"
}
}
}
]
}
}
我想要得到的是:
{
user: {
profile_photo: null,
first_name: "John",
last_name: "Doe",
addresses: [
{
{
id: 43,
country: {
name: "Iceland"
}
}
},
{
{
id: 44,
country: {
name: "Cambodia"
}
}
},
{
{
id: 45,
country: {
name: "North Korea"
}
}
}
]
}
}
有没有办法在 Rabl 中做到这一点?