Dashing Meter 读取文件 Json 并发送值
Dashing Meter read file Json and send value
我需要从 json 文件向 dashing meter 发送一个值:
解析也不起作用 contents = JSON.parse(file.read)
require 'json'
file = File.open('/mnt/json/process1.json')
contents = file.read
SCHEDULER.every '2s' do
contents["poolused"] = { label: "poolused" , value: (contents["poolused"][:value])}
send_event('synergy3', { items: contents.values})
end
这是我的 json 文件
{
"label":"value",
"PoolName": "SDS2_D2600-SAS-450G-15K",
"poolpercent": "70",
"Date": "07/23/2015 15:33:57",
"pooltotal": "3540529446912",
"poolused": "2466384969728"
}
错误:
scheduler caught exception:
undefined method `[]' for nil:NilClass
/home/toto/dashboard_v2/jobs/sample.rb:22:in `block in <top (required)>'
您的 contents
变量包含从文件中读取的 JSON 字符串。
要将其转换为哈希,您需要
contents = JSON.parse(file.read)
/opt/ruby/lib/ruby/gems/2.2.0/gems/json-1.8.3/lib/json/common.rb:155:in `parse': 757: unexpected token at '▒▒{' (JSON::ParserError)
错误:
file = File.open('/mnt/json/process1.json')
contents = JSON.parse(file.read)
使用 powershell 导出文件 json:"ASCII" 不是 UTF 16
| ConvertTo-Json | Out-file d:\products\Dashing\json\process2.json -encoding ASCII
向 dashing 发送值
require 'json'
file = File.read('./process3.json')
counts = JSON.parse(file)
SCHEDULER.every '2s' do
synergy14 = counts["poolused"]
send_event('synergy3', { value: synergy14} )
end
我需要从 json 文件向 dashing meter 发送一个值: 解析也不起作用 contents = JSON.parse(file.read)
require 'json'
file = File.open('/mnt/json/process1.json')
contents = file.read
SCHEDULER.every '2s' do
contents["poolused"] = { label: "poolused" , value: (contents["poolused"][:value])}
send_event('synergy3', { items: contents.values})
end
这是我的 json 文件
{
"label":"value",
"PoolName": "SDS2_D2600-SAS-450G-15K",
"poolpercent": "70",
"Date": "07/23/2015 15:33:57",
"pooltotal": "3540529446912",
"poolused": "2466384969728"
}
错误:
scheduler caught exception:
undefined method `[]' for nil:NilClass
/home/toto/dashboard_v2/jobs/sample.rb:22:in `block in <top (required)>'
您的 contents
变量包含从文件中读取的 JSON 字符串。
要将其转换为哈希,您需要
contents = JSON.parse(file.read)
/opt/ruby/lib/ruby/gems/2.2.0/gems/json-1.8.3/lib/json/common.rb:155:in `parse': 757: unexpected token at '▒▒{' (JSON::ParserError)
错误:
file = File.open('/mnt/json/process1.json')
contents = JSON.parse(file.read)
使用 powershell 导出文件 json:"ASCII" 不是 UTF 16
| ConvertTo-Json | Out-file d:\products\Dashing\json\process2.json -encoding ASCII
向 dashing 发送值
require 'json'
file = File.read('./process3.json')
counts = JSON.parse(file)
SCHEDULER.every '2s' do
synergy14 = counts["poolused"]
send_event('synergy3', { value: synergy14} )
end