-2

My error is on my print statement lines, it says type "Any" has no subscipt members...

if let urlContent = data {

                do {

                    let jsonResult = try 
JSONSerialization.jsonObject(with:urlContent, options: 
JSONSerialization.ReadingOptions.mutableContainers) as AnyObject

                    print(jsonResult)

                    if let items = jsonResult["items"] as? NSArray {

                        for item in items  {

                        print(item["published"])
                        print(item["title"])
                        print(item["content"])
Rakesha Shastri
  • 11,053
  • 3
  • 37
  • 50
Jogrammin
  • 13
  • 4

1 Answers1

0

You need it as an array of dictionaries it seems.

if let items = jsonResult["items"] as? [[String: Any]] { 
    for item in items  {
        print(item["published"])
        print(item["title"])
        print(item["content"])
    }
}

Depending on what content you have in the dictionary you can replace Any in [String: Any] with that type. In this case it seems to be String.

Rakesha Shastri
  • 11,053
  • 3
  • 37
  • 50