From your statement:
i want to change to [NSDictionary]
I assume it as:
Array<Dictionary<String, Any>> // using Swift v3
Although there is a more handy solution is to use SwiftyJSON library, but a non-third party solution could be:
let reply = "[{\"qty\":\"3\",\"price\":\"75000\"},{\"qty\":\"4\",\"price\":\"75000\"},{\"qty\":\"1\",\"price\":\"60000\"},{\"qty\":\"2\",\"price\":\"60000\"},{\"qty\":\"6\",\"price\":\"80000\"}]"
do {
let data = try JSONSerialization.jsonObject(with: reply.data(using: .utf8)!, options: .allowFragments) as? Array<Dictionary<String, Any>>
let firstElement: Dictionary<String, Any> = data!.first!
print("First dictionary element: \(firstElement)")
print("Quantity from first dictionary element: \(firstElement["qty"] as! String)")
}
catch{
print ("Handle error")
}
Output:
First dictionary element: ["qty": 3, "price": 75000]
Quantity from first dictionary element: 3
NOTE:
I didn't handle the nil checks and also i converted string back to data to get json object, if you already have data no need to call reply.data(using: .utf8)! instead pass your data.
As per the above comment:
You can also equate:
Array<Dictionary<String, Any>> = [[String: Any]]
Dictionary<String, Any> = [String: Any]
NSArray / NSDictionaryin Swift in conjunction withJSON.