【发布时间】:2019-11-07 15:03:00
【问题描述】:
我是红宝石新手。尝试使用 JSON.parse() 解析从 Dir.glob 命令获得的文件时出错
require 'json'
Dir.glob('**/*/.json').each do |f| # find all the .json file and loop each file
puts f
data = JSON.parse(f)
if data['Apple'].nil?
puts "skipping file #{f} as it does not have Apple"
next
end
parsed_key= File.dirname(data['Apple'][0]['red'][0]['key'])
puts parsed_key
end
`parse': 767: 'xyz/abc/config.json' (JSON::ParserError) 处出现意外标记
【问题讨论】:
-
问题肯定是文件
xyz/abc/config.json包含无效的JSON。请仔细检查并发布该文件的内容。