I am trying to parse some JSON for my app.
When trying to set the "name" value I get the error unrecognized selector sent to instance'.
This is the line of code the error happens on: self.name = [json_object objectForKey:@"name"]; (json_object is an NSDictionary and "self" is an object in CoreData)
My JSON looks like this:
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 looks like this:
#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
I believe it was working a few days ago, but I don't remember. When I started working on it today I added the "root" object. It compiles with no errors but won't parse that json.
Help?
EDIT
I changed the JSON to come back with name = "the server" and when I log that like this NSLog(@"json_object name: %@", [json_object objectForKey:@"name"]); the log says json_object name: the server but I still get the same error when I try to set that to self.name which is of type String.
I did notice that sometimes when examining the Log version of the JSON that the value inside name isn't always surrounded in quotes and as you see from the log of [json_object objectForKey:@"name"] it is showing without quotes around it. Is that the problem and why is that happening? If I look at the json straight on the web page that outputs it, there is ALWAYS quotes around the value.
EDIT 2
The full error is as follows:
-[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:
EDIT 3
I did an NSLog on "self" and this is what comes back self: <Server: 0x6143190> (entity (null); id: (null) ; data: {})
I have no clue if that is what is normal though. This is a CoreData object and I have a feeling I might have messed it up somehow.
EDIT 4
I went back and looked at the code to create a Server Object from CoreData like this:
Server *server = [NSEntityDescription
insertNewObjectForEntityForName:@"Server"
inManagedObjectContext:context];
When I ran that I now get an error that just says EXC_BAD_ACCESS so it does look like somehow that object is messed up...but I don't know how.
EDIT 5
Right, so I completely deleted the Server.h and Server.m files with my custom code, I recreated them from the CoreData object and tried that code I posted in "Edit 4" and I STILL get the same error about EXC_BAD_ACCESS....so now I have apparently gone BACKWARD rather than Forward.
Json_object class: __NSCFDictionaryis the output of that line of code. - James P. Wright@property (retain) NSString *name;in the Server interface declaration and a@synthesize name;in the implementation? - filipe