我试图解析以下字符串名为结果:JSON解析器行为以不同的方式
{
"status":0,
"id":"faxxxxx-1",
"hypotheses":[
{"utterance":"skateboard","confidence":0.90466744},
{"utterance":"skate board"},
{"utterance":"skateboarding"},
{"utterance":"skateboards"},
{"utterance":"skate bored"}
]
}
用Ruby 1.8使用obj = JSON.parse(result)
与JSON宝石。
有问题的命令是:
puts "#{obj['hypotheses'][0]}"
我的旧工作站(其硬盘去世)给我:
{"utterance" => "skateboard", "confidence" => 0.90466744}
我目前的工作站给我:
confidence0.90466744utteranceskateboard
老工作站不是由我设置的,所以我不知道当前安装了什么样的软件包一个是。
为什么在完全相同的脚本的输出中有差异? 我怎样才能使目前的一个看起来像旧的?
我完全陌生这个顺便说一句。
您显示的对象看起来是JSON结构,但与Ruby字符串不同。你忘了显示包含它的分隔单引号,并将它作为Ruby字符串吗? –