How can I convert from String
to a Dictionary
in swift
my code
Alamofire.request(apiMethod).responseJSON { response in
let statCode = response.response?.statusCode
print("URLRequest: \(String(describing: response.request!))")
print("RequestSuccess: \(String(describing: response.result.isSuccess))")
print("statusCode: \(statCode!)")
print("Response: \(String(describing: response.response!))")
print("Result: \(response.result)")
if let json = response.result.value {
print("JSON: \(json)")
}
if let data = response.data, let utf8Text = String(data: data, encoding: .utf8) {
print(utf8Text)
}
}
=======================
out code is my String
I need to change to Dictionary
:
{"result":[{"category":2,"name":"test","subCategories":[],"id":2},{"categoryType":1,"name":"التعليم والتدريب","subCategories":[{"categoryId":1,"name":"التعليم","categoryName":"التعليم والتدريب","id":1},{"categoryId":1,"name":"التدريب","categoryName":"التعليم والتدريب","id":2}],"id":1}],"targetUrl":null,"success":true,"error":null,"unAuthorizedRequest":false,"__abp":true}