现在我正在用 Ruby 从文本文件中提取信息。
那么如何从以下文本文件中提取数字“0.6748984055823062”?
{
"sentiment_analysis": [
{
"positive": [
{
"sentiment": "Popular",
"topic": "games",
"score": 0.6748984055823062,
"original_text": "Popular games",
"original_length": 13,
"normalized_text": "Popular games",
"normalized_length": 13,
"offset": 0
},
{
"sentiment": "engaging",
"topic": "pop culture-inspired games",
"score": 0.6280145725181376,
"original_text": "engaging pop culture-inspired games",
"original_length": 35,
"normalized_text": "engaging pop culture-inspired games",
"normalized_length": 35,
"offset": 370
},
我尝试过的是,我可以读取一个文件并通过以下代码逐行打印它。
counter = 1
file = File.new("Code.org", "r")
while (line = file.gets)
puts "#{counter}: #{line}"
counter = counter + 1
end
file.close
我想将数字设置为变量,以便我可以处理它。