I need to parse JSOG in my iOS application on swift. I'm trying to write deserializer by myself, but I don't know how to work with so abstract values. I have something like this, but it didn't work.
func parseElemJsog(refs: inout [String: Any], elem: Any) -> Any {
if elem is [Any] {
for subelem in elem as! [Any] {
parseElemJsog(refs: &refs, elem: subelem)
}
} else if elem is [String : Any] {
var dict = elem as! [String : Any]
if dict["@ref"] == nil {
refs[dict["@id"] as! String] = dict
dict.removeValue(forKey: "@id")
for subelem in dict {
if subelem.key != "@id" {
parseElemJsog(refs: &refs, elem: subelem.value, resutl: &resutl)
}
}
} else {
let refId = dict["@ref"] as! String
for (key, value) in refs[refId] as! [String: Any] {
dict[key] = value
}
}
} else {
}
}
And I can't use JSONDecoder
because I haven't got some model of data. Can anyone advice me some libraries or method to parse jsog? I don't know what to do me. Thanks for attention.
I want to parse something like this:
[
{
"@id": "1",
"name": "Sally",
"secretSanta": {
"@id": "2",
"name": "Bob",
"secretSanta": {
"@id": "3",
"name": "Fred",
"secretSanta": { "@ref": "1" }
}
}
},
{ "@ref": "2" },
{ "@ref": "3" }
]