ios - NSDictionary valueForKeyPath returns nill even the keypath exists -
here 2 lines app. first 1 works , value "le-05330" on label second 1 nil. doing wrong second line?
//working self.lblserialno.text = [self.partinfo valueforkeypath:@"veri.parca_bilgisi.referans_no"]; //valueforkeypath returns nil label empty. self.lblcertno.text = [self.partinfo valueforkeypath:@"veri.sertifika.sertifika_no"];
the json data on self.partinfo object below;
{ "durum": true, "hata": "", "veri": { "parca_bilgisi": { "imaj": "http://www.mywebsite.com:9898/mobapp/images/arac_hasar/arac-onsolkapi.jpg", "parca_tanimi": "Ön sol kapi", "marka": "mybrand", "marka_kodu": "70", "model": "mymodel", "model_kodu": "?", "yil": "2005", "uretici": "mymanufacturer.", "referans_no": "le-05330", "oem_no": "999999", "durum": "3", "durum_aciklama": "transferred_to_supplier" }, "onarim_servis_bilgileri": { "servis_adi": "?", "iletisim_no": "?", "islem_tarihi": "?", "hasar_dosya_no": "?" }, "sigorta_bilgileri": { "firma_adi": "?", "iletisim_no": "?", "ilgili_kisi": "?" }, "eksper_bilgileri": { "onaylama_tarihi": "?" }, "uretici_bilgileri": { "firma": "my firm as.", "imaj": "harita.jpg", "adres": "carrer de jacint verdaguer, 58, 08970", "eposta": "myr@email.es", "tel": "+36 56565 345 317", "web": "www.styaasira.es", "kayit_tarihi": "7.7.2017 13:27:44", "durum": "3" }, "sertifika": { "sertifikasyon_kurulusu": "87", "sertifika_no": "87", "gecerlilik_tarihi": "87" } } }
my code retrieving nsdictionary (dict)
nsurlsessiondatatask* task = [session datataskwithrequest:request completionhandler:^(nsdata *data, nsurlresponse *response, nserror *error) { if (error == nil) { // success nsmutabledictionary* dict = [nsjsonserialization jsonobjectwithdata:data options:kniloptions error:&error];
i eliminated service call, , tried same json string, still no chance...
nsstring *json = ... nserror *error; nsdata *data = [json datausingencoding:nsutf8stringencoding]; nsdictionary* dict = [nsjsonserialization jsonobjectwithdata:data options:nsjsonreadingmutableleaves error:&error]; self.lblissuer.text = [dict valueforkeypath:@"veri.sertifika.sertifikasyon_kurulusu"];
after several unsuccessful logical tries, decided focus on data , tried modify(simplfy) json object , try see if works on different key names. first changed name of node "sertifika" "test" , 3 sub node names "a", "b" , "c". state able value using valueforkeypath. then, changed name of nodes original, , worked!!! commented out reading json constant string service response,... wait it... worked!!!....
can tell logical going on? there sort of hashing mechanism nsdictionary had gone crazy? anyway, changing node names fails , original has solved problem...
Comments
Post a Comment