0
안녕하세요. JSON 형식의 webservice에서 응답을 받고있는 iPhone 앱을 만들고 있습니다. SBJSON Parser를 사용하여 데이터를 분석하고 있습니다.iPhone : JSON 파서를 사용하여 JSON 구문 분석 오류가 발생합니다.
데이터를 분석하는 동안 오류가 발생합니다.
I는 다음 링크를 reffered하지만 그들 중 누구도 도움 않았다있다 :
것은 무엇 잘못 될 수 있습니까?
도움을 주시면 감사하겠습니다.
코드 :
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL: [NSURL URLWithString: @"<MyWebserviceURL>"]];
/* Following function is used to convert and concate json string with url and create query string to exicute to the server.*/
[request addValue: @"application/json; charset=utf-8" forHTTPHeaderField:@"Content-Type"];
[request addValue: @"application/json; charset=utf-8" forHTTPHeaderField:@"Accept"];
NSString *msgLength = [NSString stringWithFormat:@"%d", [soapMessage length]];
[request addValue: msgLength forHTTPHeaderField:@"Content-Length"];
[request setHTTPMethod:@"POST"];
[request setHTTPBody: [soapMessage dataUsingEncoding:NSUTF8StringEncoding]];
NSData *returnData = [NSURLConnection sendSynchronousRequest:request returningResponse: nil error: nil];
/* This string will convert all the data format to string format and store it.*/
NSString *myString = [[NSString alloc] initWithData:returnData encoding:NSUTF8StringEncoding];
NSLog(@"getresponse:%@",myString);
/* This string will used get json value and split the value starting from "d".*/
//NSDictionary *d = [[myString JSONValue] objectForKey:@"d"];
NSLog(@"[myString JSONValue]: %@",[[myString JSONValue] class]);
NSDictionary *d = [[myString JSONValue] valueForKey:@"d"]; // <----- ERROR IS SHOWN HERE
콘솔 로그를 보여줍니다
getresponse:{"d":{"__type":"<CompanyName>.<AppName>.BusinessLogic.RegisterWebservice","ErrorObject":{"__type":"<CompanyName>.<AppName>.BusinessLogic.Error","ErrorMessage":"","ErrorCode":0},"AttendeeCredentials":{"__type":"<CompanyName>.<AppName>.BusinessLogic.AttendeeCredential","UserID":"abcd","Password":"abcd"},"ServerDeviceSN":"PKKPAPPKAPPKAPK090"}}
[myString JSONValue]: __NSCFString
*** Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[<__NSCFString 0xc384f30> valueForUndefinedKey:]: this class is not key value coding-compliant for the key d.'
*** First throw call stack:
(0x2eaa012 0x2b1ae7e 0x2f32fb1 0x13aa5ed 0x13168db 0x131688d 0xf6aef 0xf64b9 0xfecef 0xfe834 0x13490d5 0x1349034 0x950d8ed9 0x950dc6de)
libc++abi.dylib: terminate called throwing an exception
'SBJSON'이 (가) 깨진 경우 어떻게해야합니까? JSON은 괜찮아 보입니다. 왜 NSJSONSerialization을 사용하지 않습니까? –
json 때문일 수도 있습니다. NSLog에서 json을 가져 와서 다음 링크로 유효성을 검사하십시오 ... –
@Anil Kothari 이미 유효성을 검사했습니다. 문제는 NSDictionary * d = [[myString JSONValue] valueForKey : @ "d"]; –