views:

267

answers:

2

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.

A: 

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.

ff10
MallocStackLogging gives the following lines in the console: Json testing(22492) malloc: recording malloc stacks to disk using standard recorderJson testing(22492) malloc: process 22451 no longer exists, stack logs deleted from /tmp/stack-logs.22451.Json testing.ms0Jvs.indexJson testing(22492) malloc: stack logs being written into /tmp/stack-logs.22492.Json testing.JhgUjE.indexCant get anything useful out of the stack-logs..NSZombies doesn't seem to do any difference.
Vegar
Hm... I am not sure about how you used the malloc_history option. Try to run the App in debug mode, wait until it stops (the error occurs) - don't terminate the app, since it will terminate the process henceforth, open the Terminal end enter: malloc_history PID MA, were PID is the process ID and MA the memory adress (like 0xa4e10). Pretty much the last object mentioned there should have caused the trouble.
ff10
I added MallocStackLogging = YES to environment options.Typing malloc_history in the terminal doesn't give me much either. Not sure I have the right PID and addr, though. Used the PID that I found in activity monitor (for Json testing, not for simulator bridge). For the addr, I used a value found in the debuggers title: 'asm CFRetain 0x01b75900: json testing - Debugger'
Vegar
A: 

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];
Hemant