YAML.load_file(path)[1].each_with_index {|hash, i| File.open("json/35#{num(i+1)}.json", "w") {|f| f << JSON.pretty_generate(hash) }}def num(i) return "0" + i.to_s if i.to_s.length < 2 iend
require 'json'require 'yaml'Dir["/Users/menxu/Workspace/android/eshare/eshare-android-preview/assets/*.yaml"].each do |path| str = IO.read(path) hash = YAML.load(str) json = JSON.generate(hash) p path p path.match(/[0-9]+/) id = path.match(/[0-9]+/)[0] out_path = "./json/#{id}.json" p "convert #{out_path}" File.open(out_path,"w"){|f|f << json}end