Hello all:
I am getting JSON data from a URL and then putting it into an array, and then I need to get that data into an array of objects. Here is the struct and array (actual names hidden for confidentiality):
struct sTest: Codable
{
var a: String
var b: String
var c: String
var d: String
var e: String
var f: String
var g: String
}
var sTestArray = [sTest]()
and I get the data from the URL using this code snippet
if let jsonObj = try? JSONSerialization.jsonObject(with: data!, options: .allowFragments) as? NSDictionary
{
let theList: NSArray = jsonObj["data"] as! NSArray
and when I print the array in the Console, this is what I get:
Success
{
data = (
{
a = "a value";
b = "b value";
c = "c value";
d = "d value";
e = "e value";
f = "f value";
g = "g value";
},
and there are 144 data elements.
I am stuck on parsing this into the sTestArray. I have tried setting up a decoder, and also tried using array indexes, but no joy. Can anyone offer any assistance?
Thanks in advance!
John.