0
저는 ios dev을 사용하여 매우 새로운 것으로 지금까지 거의 모든 것을 고민해 왔습니다. 정말 정말 실망 스럽습니다.테이블 셀에 json 응답을 넣는 방법
여기에/코드가 충돌하여 /가 내 앱 흐름이 멈추는 위치를 나타 내기 위해 충돌합니다. 내가 fetchedData
- (void)fetchedData:(NSData *)responseData {
//parse out the json data
NSError* error;
NSDictionary* json = [NSJSONSerialization
JSONObjectWithData:responseData //1
options:kNilOptions
error:&error];
//NSLog(@"%@", json);
NSArray* latestLoans = [json objectForKey:@"Users"]; //2
NSEnumerator* enumerator = [latestLoans objectEnumerator];
id element;
while(element = [enumerator nextObject]) {
Result *fetchedResults = [Result init];
/*crashes here*/
fetchedResults.name = [[element objectForKey:@"User"] objectForKey:@"name"];
fetchedResults.email = [[element objectForKey:@"User"] objectForKey:@"name"];
[results addObject:fetchedResults];objectForKey:@"name"]);
}
}
결과에 대한
NSData* data = [NSData dataWithContentsOfURL:[NSURL URLWithString:@"http://192.168.2.4/iRestaurant/users"]];
[self performSelectorOnMainThread:@selector(fetchedData:)
withObject:data waitUntilDone:YES];
구현으로 JSON 데이터를 요청하고하는 것은 사용자 지정 개체이며, NSObject의의 서브 클래스입니다. Result.h를 가져 왔습니다. 또한 NSMutableArray * 결과를 현재 파일의 선언 파일에 선언했습니다. 객체를 결과으로 푸시합니다. 내가 cellForRowAtIndexPath를 구현하고 재사용 가능한 셀에 결과의 내용을 누르면됩니다
@interface Result : NSObject
@property (nonatomic, copy) NSString *name;
@property (nonatomic, copy) NSString *email;
@property (nonatomic, assign) int ID;
@end
같은 결과에 대한 헤더 파일을 찾습니다.
내 JSON 응답 코드가 발견되지 않는 객체로 인해 충돌했다
{"Users":
[{"User":
{"id":"1",
"name":"Kishor kundan",
"email":"[email protected]",
"password":"asdfasdf",
"fb_id":"1234444"
}
},
{"User":
{"id":"2",
"name":"adsfasdf",
"email":"[email protected]",
"password":"asdfasdf",
"fb_id":"123123"
}
}]
}