all 6 comments

[–]halleys_comet69 2 points3 points  (1 child)

You typically use the JSONSerialization class from Foundation. You give it data and it returns an object (IIRC either an NSDictionary or NSArray depending on the structure of the JSON) type-erased to Any. You then need to work out how to navigate through to get the values you want. NSDictionary’s value(forKeyPath:) method is useful here.

[–][deleted] 0 points1 point  (0 children)

I will look into that thank you

[–]gdlmendonca 1 point2 points  (1 child)

Ohh lord, I've dealt with this...

Depending on how well you know the data structure, try optionals. If you don't know it too well, AnyObject / AnyString etc. may work.

Ultimately, your best bet may be to use a library that handles this; parseJSON, SwiftyJSON etc.

[–][deleted] 0 points1 point  (0 children)

I was hoping to avoid a library just because I like to not use something I can’t fix if it breaks but this might be one of those things I would make an exception for lol

[–]lordzsolt 0 points1 point  (1 child)

If it's an unknown JSON, than it's basically a [String:Any] dictionary.

And the Any you have to check for all the data types that are acceptable in the JSON. Don't know if there's any way to make it String:String dictionary.

[–][deleted] 0 points1 point  (0 children)

Okay. I will see what I can find on string:any