Advice for going from CSV > JSON > Swift objects

谁说胖子不能爱 提交于 2020-05-17 09:56:05

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!