내 응용 프로그램 용 JSON을 구문 분석하려고합니다. "name"값을 설정하려고하면 unrecognized selector sent to instance'
오류가 발생합니다.
이 오류가 발생하는 코드의 라인 :CoreData, JSON "인식 할 수없는 셀렉터가 인스턴스로 전송되었습니다."
json_object: {
draftstatus = "isdraftfull.php";
getcard = "getcard.php";
getpack = "getpack.php";
imageextension = ".jpg";
images = "images/small/";
joindraft = "joindraft.php";
joindraftmenu = "getjoindraftmenu.php";
login = "loginasuser.php";
name = "the server";
passpack = "passpack.php";
playerdraftstatus = "getplayerdraftstatus.php";
signup = "signup.php";
userexists = "checkifuserexists.php";
usesetidforimagepath = false;
}
Server.h 외모 : self.name = [json_object objectForKey:@"name"];
내 JSON은 다음과 같습니다 (JSON_OBJECT가있는 NSDictionary와 "자기"입니다 CoreData의 개체입니다) 다음과 같이하십시오 :
#import <CoreData/CoreData.h>
#import "JSON.h"
@interface Server : NSManagedObject
{
NSMutableData *responseData;
}
@property (nonatomic, retain) NSString * playerdraftstatus;
@property (nonatomic, retain) NSString * signup;
@property (nonatomic, retain) NSNumber * usesetidforimagepath;
@property (nonatomic, retain) NSString * login;
@property (nonatomic, retain) NSString * imageextension;
@property (nonatomic, retain) NSString * userexists;
@property (nonatomic, retain) NSString * getcard;
@property (nonatomic, retain) NSString * passpack;
@property (nonatomic, retain) NSString * draftstatus;
@property (nonatomic, retain) NSString * joindraftmenu;
@property (nonatomic, retain) NSString * getpack;
@property (nonatomic, retain) NSString * joindraft;
@property (nonatomic, retain) NSString * images;
@property (nonatomic, retain) NSNumber * isdefaultserver;
@property (nonatomic, retain) NSString * root;
@property (nonatomic, retain) NSString * name;
- (id) initWithWebAddress:(NSString *) address;
- (id) initWithWebAddressAsyn:(NSString *) address;
- (void) fillFromJSON:(NSDictionary *) json_object;
- (void) saveServer;
@end
나는 며칠 전부터 일했다고 생각하지만, 기억이 안납니다. 오늘 작업을 시작했을 때 "루트"개체를 추가했습니다. 오류없이 컴파일되지만 해당 json을 구문 분석하지 않습니다.
도움 말?
편집
나는 name = "the server"
로 돌아와하기 위해 JSON을 변경하고 나는이 NSLog(@"json_object name: %@", [json_object objectForKey:@"name"]);
같은 로그가 나는 String 형이다 self.name
해당 설정하려고 할 때 json_object name: the server
는하지만 난 여전히 같은 오류가 말한다 로그인 할 때 .
때로는 이름 내부의 값이 항상 따옴표로 묶여 있지 않으며, [json_object objectForKey:@"name"]
의 로그에서 볼 수있는 JSON의 로그 버전을 따옴표없이 표시 할 때주의해야합니다. 그게 문제이고 그 일은 왜 일어나는 것입니까? 내가 출력하는 웹 페이지에서 곧바로 json을 보면 값 주변에 항상 인용 부호가 있습니다.
EDIT 2
전체 오류는 다음과 같다 :
-[Server setName:]: unrecognized selector sent to instance 0x61036e0
2010-11-19 15:46:10.113 TCGDraft[57953:207] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[Server setName:]: unrecognized selector sent to instance 0x61036e0'
*** Call stack at first throw:
편집
3 나는 "자기"에 NSLog를하고이 self: <Server: 0x6143190> (entity (null); id: (null) ; data: {})
내가 더이 다시 온다 무엇인가 실마리가 있다면 그것은 정상입니다. 이것은 CoreData 객체이며 어떻게 든 엉망이되었을 것 같은 느낌이 들었습니다.
EDIT 4
난 다시 가서 같은 CoreData에서 서버 개체 작성하는 코드를 보았다 : 나는 지금 너무 그것을 EXC_BAD_ACCESS
을 말한다 오류가 발생하는 것을 실행하면
Server *server = [NSEntityDescription
insertNewObjectForEntityForName:@"Server"
inManagedObjectContext:context];
을 어떻게 든 그 물체가 엉망이 된 것처럼 보이지만 ... 나는 어떻게해야할지 모르겠다.
5
오른쪽, 그래서 나는 완전히 내 사용자 지정 코드로 Server.h 및 Server.m 삭제 된 파일을 편집, 난 CoreData 개체에서 그들을 다시 내가 "편집 4"에 게시 된 해당 코드를 시도하고 I EXC_BAD_ACCESS ....에 대해서도 같은 에러가 나옵니다. 그래서 앞으로 Forward보다는 BACKWARD로 넘어갔습니다.
[JSON_OBJECT objectForKey "이름"@]; null 값을 리턴합니다. 확인해 봐. – jfalexvijay
"json_object"아래의 "name"이 "Default Server"라고 말하면 null 값을 반환 할 수 있습니까? –
json_object가 NSDictionary입니까? NSLog (@ "class : % @", [json_object class])를 수행하십시오. 그리고 그것이 무엇을 반환하는지보십시오. –