0
NSURLConnection
을 사용하여 webservice 문자열을 호출하고 있는데 성공 방법이 NSURLConnection
인 경우 잘못된 데이터가 표시됩니다. 브라우저에 동일한 URL
을로드하면 올바른 응답이 표시됩니다. 아래 코드를 사용하고 있습니다.Json 응답이 잘못된 데이터를 제공하고 있습니다
NSData *mydata=[srtRes dataUsingEncoding:NSUTF8StringEncoding];
NSError *e;
NSMutableArray *returnArry =[[NSMutableArray alloc]init];
returnArry = [NSJSONSerialization JSONObjectWithData:mydata options:NSJSONReadingMutableContainers error:&e];
이 문제를 해결하는 방법. 친절하게 제안과 답변을하십시오.
이// In .h class
@property (nonatomic,retain) NSMutableData *responseData;
@property (nonatomic, retain) NSMutableArray *temp_arr;
// In .m class
@synthesize responseData;
@synthesize temp_arr;
- (void)viewDidLoad
{
NSString *[email protected]"http://your urls";
self.responseData=[NSMutableData data];
NSURLConnection *connection=[[NSURLConnection alloc]initWithRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:urlString]] delegate:self];
NSLog(@"connection====%@",connection);
}
JSON 구문 분석의 위임 방법은 :
은 JSON 구문이 올바른지? 확인 했니? 그렇지 않으면 http://jsonlint.com/ – Noor
에서 확인하십시오. validator에서 특정 URL을 주면 올바른 데이터가 왜 내 코드에 없는지 알 수 있습니다. – Romance
반드시 그렇지는 않습니다. 먼저 데이터를로드합니다. 유효하지 않은 JSON이 유효한 데이터입니다. – Noor