ButtonMasterBot
ButtonMasterBot

Reputation: 317

Cannot Subscript Value of Type JSON to an Index of Type JSON Error in Swift

I am using Wunderground to gather history data, using SwiftyJSON. However, in the API, a section called "dailysummary" is curtained off in an array. Abbreviated, it looks something like this:

"history": {
    "dailysummary": [{
        "stuff": "here"
    ]}

I had tried to isolate the content inside the array with this:

var jsonData = json["history"]["dailysummary"]
var arrayData = json["history"]["dailysummary"][0]
jsonData = json["history"]["dailysummary"][arrayData]

This code returns an error saying it cannot subscript a value of type 'JSON' with an index of type 'JSON'. Is there any way to make this work, or a way to get the data from to array in this format?

Upvotes: 1

Views: 2720

Answers (1)

zaph
zaph

Reputation: 112857

You want something like:

var arrayData = json["history"]["dailysummary"][0]["stuff"].

arrayData is a dictionary.

Upvotes: 1

Related Questions