I'm fairly new to Swift and trying to get a JSON array that comes back from Alamofire into a normal Swift array.
var dpoParamArr = JSON([])
//Alamofire code here and I get the value back below which is Parameters
self.dpoParamArr = JSON(dictMain)["Parameters"]
print(self.dpoParamArr.arrayValue.map({($0.dictionaryValue["name"]?.stringValue)!}))
print(self.dpoParamArr.arrayValue.map({($0.dictionaryValue["value"]?.stringValue)!}))
This is the print result: ["PAY_REQUEST_ID", "CHECKSUM"] ["5FB1DDBB-D637-3DC3-C0AF-288EFF98012C", "4FD856821E0F6D238F8346175227FF04"]
How do I get my array to have a key and value
"Parameters": [
{
"name": "PAY_REQUEST_ID",
"value": "94DEE72B-F75C-453F-1280-F1B26BBFD98E"
},
{
"name": "CHECKSUM",
"value": "9171405E05C9C9B7D4B6FF497FC4AE50"
}
]
My end goal is to get the name and value variables for both JSON nodes.
self.dpoParamArr.forEach { postFormHtml += "<input type='hidden' name='\($0.key)' value='\($0.value)'></input>" }should do the trick then. But it'd be nice to add your end-goal to your question by editing it, not only in comment.