Using SWIFT4 and Decodable I am trying to parse the first result 26537 from the array
pageids at this JSON URL, see JSON IMAGE with the following code but I get nil value everytime; the issue seems to be with the fact that I can't assign any variable to represent pageids[0] ? How ? any suggestion ? How do you get the ID number in pageids ?CODE
struct WikiData: Decodable {
var batchcomplete: String
var query: [Query]
var pageids : [Pageids]
}
struct Query : Decodable {
var pageids : [Pageids]
}
struct Pageids : Decodable {
// need first item of the array as seen in JSON below
}
let jsonData = try! Data(contentsOf: url)
let datastring = String(data: jsonData, encoding: .utf8)
print (datastring as Any) /
let id = try? JSONDecoder().decode(WikiData.self, from: jsonData)
print(WikiData?.pageids as Any)JSON EXTRACT
{"batchcomplete":"","query":{"pageids":["26537"],"pages":{"26537":{"pageid":26537,"ns":0,"title":"Rose","extract":"A rose"}}}}