我试图公开一个作为 JSON 字符串保存在数据库中的列。但它显示为字符串。任何帮助,将不胜感激。
实体样本:
class Entity < Grape::Entity
expose :id
expose :name
expose :credentials # this is json string
end
实际反应:
[
{
"id": 1,
"name": "Foo",
"credentials": "[{\"name\":\"key\",\"label\":\"Key\"},{\"name\":\"key2\",\"label\":\"Key2\"}]"
}
]
预期反应:
[
{
"id": 1,
"name": "Foo",
"credentials": [
{
"name": "key",
"label": "Key"
},
{
"name": "key2",
"label":"Key2"
}
]
}
]