我有一个要用Ruby解析的字符串:
string = '{"desc":{"someKey":"someValue","anotherKey":"value"},"main_item":{"stats":{"a":8,"b":12,"c":10}}}'
有没有简单的方法来提取数据?
我有一个要用Ruby解析的字符串:
string = '{"desc":{"someKey":"someValue","anotherKey":"value"},"main_item":{"stats":{"a":8,"b":12,"c":10}}}'
有没有简单的方法来提取数据?
这看起来有JavaScript Object Notation (JSON)个.您可以解析驻留在某个变量(例如json_string
)中的JSON,如下所示:
require 'json'
JSON.parse(json_string)
If you’re using an older Ruby, you may need to install the json gem.
There are also other implementations of JSON for Ruby that may fit some use-cases better: