응답을 this url에서 json으로 변환하려면 어떻게해야합니까? do valueForUndefinedKey:]: this class is not key value coding-compliant for the key ANeighborhood.'
다음 코드에서 NSLog(@"array 5656 = %@", array);
의 이스케이프 시퀀스로 인한 오류가 발생했습니다.http 요청을 json으로 변환하십시오.
NSURL * url = [NSURL URLWithString:urlString];
NSError *error;
NSString *jsonString = [NSString stringWithContentsOfURL:url encoding:NSUTF8StringEncoding error:&error];
if(!error)
{
NSData *jsonData = [jsonString dataUsingEncoding:NSUTF8StringEncoding];
NSDictionary *jsonDict = [NSJSONSerialization JSONObjectWithData:jsonData options:NSJSONReadingAllowFragments error:Nil];
NSDictionary *dict = [jsonDict valueForKey:@"ProspectReportResult"];
NSString *jsonString = [NSString stringWithFormat:@"%@", dict];
NSLog(@"String 444 = %@", jsonString);
NSString *jsonString1=[jsonString stringByAppendingFormat:@"%s","]"];
NSString *[email protected]"[";
NSString *jsonString2=[jsonString12 stringByAppendingString: jsonString1];
NSString *[email protected]"}{";
jsonString2= [jsonString2 stringByReplacingOccurrencesOfString:jsonString22 withString:@"}][{"];
NSLog(@"String 999 = %@", jsonString2);
//jsonString2 = [jsonString2 stringByReplacingOccurrencesOfString:@"\\" withString:@""];
NSArray *array12=[jsonString2 componentsSeparatedByString: @"]"];
NSLog(@"Aray2323 = %@", array12);
for(NSString* str in array12)
{
NSString *str1=[str stringByAppendingFormat:@"%s","]"];
str1 = [str1 stringByReplacingOccurrencesOfString:@"\\" withString:@""];
NSArray *array = [NSArray arrayWithObject:str1];
NSLog(@"array 5656 = %@", array);
for (NSDictionary *dict in array) {
NSLog(@"Dictionary :%@",dict);
prospect = [[ProspectData alloc]init];
[prospectArray addObject:prospect];
prospect.ANeighborhood= (NSString*)[dict valueForKey:@"ANeighborhood"];
prospect.BClientName= (NSString*)[dict valueForKey:@"BClientName"];
prospect.CSoldStatus=(NSString*)[dict valueForKey:@"CSoldStatus"];
prospect.DFirstVisit=(NSString*)[dict valueForKey:@"DFirstVisit"];
prospect.ELastVisit=(NSString*)[dict valueForKey:@"ELastVisit"];
prospect.FNoOfVisit=(NSString*)[dict valueForKey:@"FNoOfVisit"];
prospect.GTypeOfLead=(NSString*)[dict valueForKey:@"GTypeOfLead"];
prospect.HPurchRealtor=(NSString*)[dict valueForKey:@"HPurchRealtor"];
prospect.IClientSource=(NSString*)[dict valueForKey:@"IClientSource"];
}
}
//[self.tableView reloadSections:[NSIndexSet indexSetWithIndex:0] withRowAnimation:UITableViewRowAnimationNone];
[self.tableView reloadData];
self.tableView.tableFooterView = [[UIView alloc] initWithFrame:CGRectZero];
}
이동은 json.org와 JSON 구문을 공부합니다. 가장 바깥 쪽 구조는 배열이 아닌 "객체"(사전)입니다. 인터넷에서 예를 복사하여 JSON을 처리 할 수 없으므로 이해해야합니다. –
실제로'ProspectReportResult' 키 아래의 JSON 값이 유효하지 않다고 생각합니다. ''{{..}, {..}, ..]'의 배열을','로 구분하여 사용해야합니다. 응답을 수정해야합니다. – Amar
@Amar 그게 내가 NSString 클래스 참조를 사용하여 달성하려했다. 응답을 고칠 정도로 논쟁했습니다. – user3244372