I want to combine 3 json results into one for looping into later.
I have tried every single combination on the internet yet I'm still stuck a dead end. I am calling an API call that in response, receives json data. I want to get the first 3 results and return that data to the calling method however, I just cannot find a way to find the desired response.
var data: JSON = []
func getData(forKey url: URL, completion: @escaping ([JSON]) -> Void){
AF.request(url).responseJSON { (responseData) -> Void in
if((responseData.result.value) != nil) {
let swiftyJsonVar = JSON(responseData.result.value!)
for loopID in 0 ... 2{
print(swiftyJsonVar["results"][loopID])
}
}
return completion([self.data])
}
}
My desired results are
[
{
"name": "james",
"location": "Mars"
},
{
"name": "james",
"location": "Mars"
},
{
"name": "james",
"location": "Mars"
}
]
When, in my loop, I receive, x 3
{
"name": "james",
"location": "Mars"
}