开发者

Creating this array format

开发者 https://www.devze.com 2023-03-28 10:13 出处:网络
I need help in creating a json sting in the following format. [{\"k开发者_StackOverflow社区ey\": \"hello world\", \"value\": \"hello world\"}, {\"key\": \"movies\", \"value\": \"movies\"}, {\"key\":

I need help in creating a json sting in the following format.

[{"k开发者_StackOverflow社区ey": "hello world", "value": "hello world"}, {"key": "movies", "value": "movies"}, {"key": "ski", "value": "ski"}, {"key": "snowbord", "value": "snowbord"}]

my input data will be categories with following attributes.

:id, :name, :active

and I would like to use the :id as key and :name as value.


input_data.map { |d| { "key" => d.id, "value" => d.name } }
0

精彩评论

暂无评论...
验证码 换一张
取 消