I need to convert an array of strings that I get from an xml, into a json file and then save it in a sqlite database.
I have this code:
do {
let jsonData = try NSJSONSerialization.dataWithJSONObject(dictionaryOrArray, options: NSJSONWritingOptions.PrettyPrinted)
} catch let error as NSError{
print(error.description)
}
But I get this error:
Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Invalid type in JSON write'
The array I believe in the parser xml:
func parser(parser: NSXMLParser, didEndElement elementName: String, namespaceURI: String?, qualifiedName qName: String?) {
if elementName == "title" {
let title: String = foundCharacters.stringByTrimmingCharactersInSet(NSCharacterSet.whitespaceAndNewlineCharacterSet())
self.currentlyConstructingArticle.titulo = title
}
else if elementName == "img" {
let imgString:String = foundCharacters.stringByTrimmingCharactersInSet(NSCharacterSet.whitespaceAndNewlineCharacterSet())
self.currentlyConstructingArticle.imagen = imgString
}
else if elementName == "description" {
let descripcion: String = foundCharacters.stringByTrimmingCharactersInSet(NSCharacterSet.whitespaceAndNewlineCharacterSet())
self.currentlyConstructingArticle.descripcion = descripcion
}
else if elementName == "item" {
self.articles.append(self.currentlyConstructingArticle)
}
self.foundCharacters = ""
}