Below is the sample code to parse your json string
// I've escaped the double quotes so that it can run, you don't need to do it because you already have the string
let responseStr = "[{\"Loc_District\":8119,\"districtname\":\"अजमेर \",\"District_NameEng\":\"AJMER\"},{\"Loc_District\":8104,\"districtname\":\"अलवर \",\"District_NameEng\":\"ALWAR\"},{\"Loc_District\":8125,\"districtname\":\"बांसवाड़ा\",\"District_NameEng\":\"BANSWARA\"},{\"Loc_District\":8128,\"districtname\":\"बारां \",\"District_NameEng\":\"BARAN\"},{\"Loc_District\":8115,\"districtname\":\"बाड़मेर \",\"District_NameEng\":\"BARMER\"},{\"Loc_District\":8105,\"districtname\":\"भरतपुर \",\"District_NameEng\":\"BHARATPUR\"},{\"Loc_District\":8122,\"districtname\":\"भीलवाडा \",\"District_NameEng\":\"BHILWARA\"},{\"Loc_District\":8101,\"districtname\":\"बीकानेर \",\"District_NameEng\":\"BIKANER\"},{\"Loc_District\":8121,\"districtname\":\"बून्दी \",\"District_NameEng\":\"BUNDI\"},{\"Loc_District\":8126,\"districtname\":\"चित्तौड़गढ़ \",\"District_NameEng\":\"CHITTORGARH\"},{\"Loc_District\":8102,\"districtname\":\"चूरू \",\"District_NameEng\":\"CHURU\"},{\"Loc_District\":8109,\"districtname\":\"दौसा \",\"District_NameEng\":\"DAUSA\"},{\"Loc_District\":8106,\"districtname\":\"धौलपुर \",\"District_NameEng\":\"DHOLPUR\"},{\"Loc_District\":8124,\"districtname\":\"डूंगरपुर \",\"District_NameEng\":\"DUNGARPUR\"},{\"Loc_District\":8099,\"districtname\":\"गंगानगर \",\"District_NameEng\":\"GANGANAGAR\"},{\"Loc_District\":8100,\"districtname\":\"हनुमानगढ \",\"District_NameEng\":\"HANUMANGARH\"},{\"Loc_District\":8110,\"districtname\":\"जयपुर \",\"District_NameEng\":\"JAIPUR\"},{\"Loc_District\":8114,\"districtname\":\"जैसलमेर \",\"District_NameEng\":\"JAISALMER\"},{\"Loc_District\":8116,\"districtname\":\"जालोर \",\"District_NameEng\":\"JALORE\"},{\"Loc_District\":8129,\"districtname\":\"झालावाड \",\"District_NameEng\":\"JHALAWAR\"},{\"Loc_District\":8103,\"districtname\":\"झुंझुंनु \",\"District_NameEng\":\"JHUNJHUNU\"},{\"Loc_District\":8113,\"districtname\":\"जोधपुर \",\"District_NameEng\":\"JODHPUR\"},{\"Loc_District\":8107,\"districtname\":\"करौली \",\"District_NameEng\":\"KAROULI\"},{\"Loc_District\":8127,\"districtname\":\"कोटा \",\"District_NameEng\":\"KOTA\"},{\"Loc_District\":8112,\"districtname\":\"नागौर \",\"District_NameEng\":\"NAGAUR\"},{\"Loc_District\":8118,\"districtname\":\"पाली \",\"District_NameEng\":\"PALI\"},{\"Loc_District\":8131,\"districtname\":\"प्रतापगढ \",\"District_NameEng\":\"PRATAPGARH\"},{\"Loc_District\":8123,\"districtname\":\"राजसमन्द \",\"District_NameEng\":\"RAJSAMAND\"},{\"Loc_District\":8108,\"districtname\":\"सवाई माधोपुर \",\"District_NameEng\":\"SAWAI MADHOPUR\"},{\"Loc_District\":8111,\"districtname\":\"सीकर \",\"District_NameEng\":\"SIKAR\"},{\"Loc_District\":8117,\"districtname\":\"सिरोही \",\"District_NameEng\":\"SIROHI\"},{\"Loc_District\":8120,\"districtname\":\"टोंक \",\"District_NameEng\":\"TONK\"},{\"Loc_District\":8130,\"districtname\":\"उदयपुर \",\"District_NameEng\":\"UDAIPUR\"}]"
// Convert your response string to data or if you've data then pass it directly
let jsonData = responseStr.data(using: .utf8)
do {
let json = try JSONSerialization.jsonObject(with: jsonData!, options: [])
if let array = json as? [[String : AnyObject]] {
for obj in array {
let distName = obj["districtname"]
print("\(String(describing: distName!))")
}
}
}
catch {
print("Couldn't parse json \(error)")
}
7
solved how do i get particular key value from string in swift4