ios - Parse JSON text in a textfield (My result is NULL) -
i making ios application communicate database via api. api sends valid json application application gives no error result: null.
here code ios app:
// start hud mbprogresshud *hud = [mbprogresshud showhudaddedto:self.view animated:yes]; hud.labeltext = @"zoeken..."; return true; } - (void)requestfinished:(asihttprequest *)request { [mbprogresshud hidehudforview:self.view animated:yes]; if (request.responsestatuscode == 400) { textview.text = @"invalid code"; } else if (request.responsestatuscode == 403) { textview.text = @"code used"; } else if (request.responsestatuscode == 204) { textview.text = @"no content"; } else if (request.responsestatuscode == 412) { textview.text = @"precondition failed"; } else if (request.responsestatuscode == 200) { nsstring *responsestring = [request responsestring]; nsdictionary *responsedict = [responsestring jsonvalue]; // nsstring *naam = [responsedict objectforkey:@"deb_nr"]; nsstring *part0 = [responsedict objectforkey:@"klntnr"]; nsstring *part1 = [responsedict objectforkey:@"klntnm"]; nsstring *part2 = [responsedict objectforkey:@"adrs"]; nsstring *show = [nsstring stringwithformat:@"\r%@\r%@\r%@" , part0 , part1 , part2 ]; // if ([unlockcode compare:@"com.razeware.test.unlock.cake"] == nsorderedsame) { textview.text = [nsstring stringwithformat:@"resultaten: %@", show]; // } else { // textview.text = [nsstring stringwithformat:@"resultaat: %@", unlockcode]; // } } else { textview.text = @"unexpected error api error"; } } - (void)requestfailed:(asihttprequest *)request { [mbprogresshud hidehudforview:self.view animated:yes]; nserror *error = [request error]; textview.text = error.localizeddescription; } @end
thanks in advance,
maurice.
it if show json string; try this
else if (request.responsestatuscode == 200) { nserror* error; nsstring *responsestring = [request responsestring]; nsarray *responseobj = [nsjsonserialization jsonobjectwithdata: [responsestring datausingencoding:nsutf8stringencoding] options: nsjsonreadingmutablecontainers error: &error]; nsstring *part0=@""; nsstring *part1=@""; nsstring *part2=@""; (int i=0; i<[responseobj count]; i++) { nsdictionary *datadict = [responseobj objectatindex:i]; nsstring *part0 = [datadict objectforkey:@"klntnr"]; nsstring *part1 = [datadict objectforkey:@"klntnm"]; nsstring *part2 = [datadict objectforkey:@"adrs"]; } nsstring *show = [nsstring stringwithformat:@"\r%@\r%@\r%@" , part0 , part1 , part2 ]; textview.text = [nsstring stringwithformat:@"resultaten: %@", show]; }
Comments
Post a Comment