Reputation: 12898
UPDATE:
I found that the reason for the previous error was an error in the documentation.
The method should be named proxyForJson, not jsonProxyObject...
But I'm still stuck, though.
I now get an EXC_BAD_ACCESS error inside stringWithObject some where. Any clues?
UPDATE 2:
My proxyForJson implementation is a cut-n-paste from then documentation:
- (id)proxyForJson {
return [NSDictionary dictionaryWithObjectsAndKeys:
Navn, @"Navn",
Adresse, @"Adresse",
Alder, @"Alder",
nil];
}
Trying to make json serialization work for my custom objective-c class.
As I understand the documentation, json-framework can serialize custom objects, if they implement the jsonProxyObject method.
So I have this class:
@interface MyObject : NSObject {
NSString *Name;
NSString *Addresse;
NSInteger Age;
}
@property (nonatomic, retain) NSString *Name;
@property (nonatomic, retain) NSString *Addresse;
@property (nonatomic, assign) NSInteger Age;
- (id)jsonProxyObject;
@end
And I try to serialize an array with some instances in it:
[json stringWithObject:list error:&error];
But all I get is he following error:
"JSON serialisation not supported for MyObject"
I guess the jsonWriter can't find my jsonProxyObject method for some reason, buy why?
Regards.
Upvotes: 2
Views: 1316
Reputation: 1
In NSString, there is no stringWithObject:
method. You should try using stringWithFormat:
instead.
Upvotes: 0
Reputation: 19826
I am not sure whether this is the right thing to do but defining the class as follows, solves the problem:
@interface MyObject : NSObject {
NSString *Name;
NSString *Addresse;
NSInteger *Age;
}
@property (nonatomic, retain) NSString *Name;
@property (nonatomic, retain) NSString *Addresse;
@property (nonatomic, retain) NSInteger *Age;
- (id)jsonProxyObject;
@end
Then initializing the variable as:
Age = [[NSNumber alloc] initWithInt:32];
Upvotes: 0
Reputation: 3147
Have you tried to turn on NSZombies and MallocStackLogging in your Executable Info pane to check the source of the EXC_BAD_ACCESS? If not, you might try this and check the console for the output. EXC_BAD_ACCESS is often an error caused by over-releasing an object somewhere.
Upvotes: 0