问题
New to programming, hoping I can get some advice on the best way to approach this.
I have a CSV file with data I need to convert to custom objects in Swift. The custom type is mostly made up of String and [String] properties.
I was told working with CSVs is difficult, especially if my data contains special characters (it does), and I'd have more flexibility using JSON. So I converted the CSV to JSON using an online tool, imported it, and attempted to decode it.
The issue is, the CSV cells that need to become [String] aren't formatted as arrays in the CSV. They're just values separated by commas or line breaks, so the online tool interprets the whole cell as being one long string.
So basically, I need a way to convert those cells into arrays. The question is, is that best done to the CSV before converting to JSON? Or to the JSON before or after decoding? Or perhaps I should make an intermediate object type with just strings, convert the string properties to arrays, and then create a new object of the correct type?
Or is there some better method to all of this?
来源:https://stackoverflow.com/questions/55755786/advice-for-going-from-csv-json-swift-objects