Create JSON of one dimension Ruby -


i want have this:

["(gka) goroka, goroka, papua new guinea"]

instead of:

[ [ "(gka)", "goroka", "goroka", "papua new guinea" ] ]

i have code far:

@aeropuertos = ""     f = file.open("./public/aeropuertos/aeropuertos.cvs", "r")     f.each_line { |line|       fields = line.split(':')        if (fields[2] == "n/a")         @line =  "(" << fields[1] << ")" << ",," << fields[3] << "," << fields[4]       else         @line =  "(" << fields[1] << ")"  << "," << fields[2] << "," << fields[3] << "," << fields[4]       end       @aeropuertos += @line << "\n"     }     return csv.parse(@aeropuertos).to_json 

what should do?

@aeropuertos = ""

f = file.open("./public/aeropuertos/aeropuertos.cvs", "r") f.each_line { |line|   fields = line.split(':')    if (fields[2] == "n/a")     @line =  "(" << fields[1] << ")" << ",," << fields[3] << "," << fields[4]   else     @line =  "(" << fields[1] << ")"  << "," << fields[2] << "," << fields[3] << "," << fields[4]   end   @aeropuertos += @line << "\n" } res = [] csv.parse(@aeropuertos).each |c|     res << c.join(',') end return res.to_json 

Comments

Popular posts from this blog

c# - SharpSVN - How to get the previous revision? -

c++ - Is it possible to compile a VST on linux? -

url - Querystring manipulation of email Address in PHP -