3
从JSON文件中的值这是一个sample.json文件如下解析在红宝石
{
"name": "Jack (\"Bee\") Nimble",
"format": {
"shape": "rect",
"width": 1920,
"height": 1080,
"interlace": false,
"framerate": 24
}
}
在sample.json文件已被打开的规格文件。
describe Samplespec do
before :all do
@jsonfile = File.open('sample.json').read
@file_json = Samplespec.new(@jsonfile)
end
我在sample.rb文件
require 'json'
def initialize(val)
@parsed_val = JSON.parse(val)
end
这似乎并不工作写这个。请帮忙。谢谢
似乎没有工作?你会得到什么错误,会发生什么? – 2012-08-01 13:06:11
sample.json文件原样显示{“name”:“Jack(\”Bee \“)Nimble”, “format”:{ “shape”:“rect”, “width”: 1920, “height”:1080, “interlace”:false, “framerate”:24 } } – user1568617 2012-08-01 13:08:40