I'm trying to read a json array data as below with my code but I'm getting empty result all the time while I can print the whole data. Please where would be my issue?
I've read this topic but I couldn't get the result. Topic Link
{"Cars":[{"Brand":"Alfa Romeo"},{"Brand":"Audi"},{"Brand":"BMW"},{"Brand":"Citroen"},{"Brand":"Dacia"},{"Brand":"Fiat"},..........
My code
func getData(){
var url = "http://test.net/services/test.php"
var request = HTTPTask()
request.GET(url, parameters: nil, completionHandler:
{
(response:HTTPResponse) in
var jsonData = response.responseObject as! NSData
var json = JSON(data: jsonData)
println("All data \(json)")
dispatch_async(dispatch_get_main_queue(),
{
println(json["Cars"]["Brand"].stringValue)
})
})
}
json["Cars"]
is an array, so for example to get the first item via SwiftyJSON:In a JSON string,
{
and}
are delimiters for dictionaries, whereas[
and]
are delimiters for arrays.EDIT:
Following your comment, yes, you can loop over the array: