I am having an api in which after parsing json the response gets as below mentioned and after that I had removed slashes also but unable to save it into dictionary format can anyone help me how to implement this ?
Here is my code
func productListSortDownloadJsonWithURL() {
let url = URL(string: sortIndicesURL)!
var request = URLRequest(url: url as URL)
request.httpMethod = "GET"
request.addValue("Basic Z29tZXRvb2FkOm55UWREZ1ZYMWdYU1FkMmhHWEpN", forHTTPHeaderField: "Authorization")
let task = URLSession.shared.dataTask(with: request) { (data, response, error) in
if error != nil { print(error!); return }
do {
if let jsonObj = try! JSONSerialization.jsonObject(with: data!, options: .allowFragments) as? String {
print(jsonObj)
self.secondIndices = jsonObj.replacingOccurrences(of:"\"", with: "")
DispatchQueue.main.async {
}
}
} catch {
print(error)
}
}
task.resume()
}
here is my json data
"{\"1\":{\"attribute\":\"price_index\",\"sort\":\"desc\",\"sortLabel\":\"Highest price\"},\"0\":{\"attribute\":\"price_index\",\"sort\":\"asc\",\"sortLabel\":\"Lowest price\"},\"2\":{\"attribute\":\"rating_summary\",\"sort\":\"desc\",\"sortLabel\":\"Top Rated\"}}"