如何在ruby中获取JSON数组中的键值?

时间:2015-09-24 11:05:09

标签: ruby json

我有以下 JSON -Structure:

{ "A" : "1", "B" : "2", "RandomOtherName" : "54738" }

如何在ruby中提取关键值("A""B""RandomOtherName",...)(最好是在数组中)?

1 个答案:

答案 0 :(得分:6)

require 'json'
data = '{ "A" : "1", "B" : "2", "RandomOtherName" : "54738" }'
JSON.parse(data).keys # => ["A", "B", "RandomOtherName"]