views:

349

answers:

2

at first, sry for my english... :)

I'm using the YAJL Framework http://github.com/gabriel/yajl-objc

My file look like this:

[ [ 3753700,  
{ "altitude" : 36950,  
      "heading" : 129.918421384319,  
      "latitude" : 47.554033252495699,  
      "longitude" : 8.2125612837369903,  
      "pointType" : "EXTRAPOLATED",  
      "speed" : 455.04395392093699,  
      "timestamp" : 1273252673301,  
      "verticalRate" : 0.0  
    }   
  ],  
  [ 3753700,  
    { "altitude" : 36950,  
      "heading" : 129.918421384319,  
      "latitude" : 47.552708437680799,   
      "longitude" : 8.2149074662342798,  
      "pointType" : "EXTRAPOLATED",  
      "speed" : 455.04395392093699,  
      "timestamp" : 1273252674555,  
      "verticalRate" : 0.0  
    }  
  ]  
]

I've tried it in x-variant, but I always get a 'NSInvalidArgumentException' from console:

2010-05-07 20:17:30.998 testApp[2365:207] *** -[NSConcreteData yajl_JSON]: unrecognized selector sent to instance 0x1353d0
2010-05-07 20:17:31.006 testApp[2365:207] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[NSConcreteData yajl_JSON]: unrecognized selector sent to instance 0x1353d0'

How to read the data correctly?

thx for help

A: 

Did you add the ‘-ObjC‘ and ‘-load_all‘ commands to your linker flags for your target? If they're not present then categories present in static libraries will not be available in the compiled binary.

From the docs: Under 'Other Linker Flags' in your target, add -ObjC and -all_load (So NSObject+YAJL category is loaded).

Ashley Clark
yes I did. also with the flags I get the error
mekanics
k sry a add the flags to the wrong parameterthx you
mekanics
now it don't crash with the iPhone simulator, but with the iPhone (the same error)
mekanics
A: 

I'm not aware of the framework you are using but have you tried the json-framework available on Google Code? I used it in several projects and never had any problems with it.

+ (NSString *)stringWithUrl:(NSURL *)url {
    NSURLRequest *urlRequest = [NSURLRequest requestWithURL:url
                                                cachePolicy:NSURLRequestReturnCacheDataElseLoad
                                            timeoutInterval:30];
    NSData *urlData;
    NSURLResponse *response;
    NSError *error;

    urlData = [NSURLConnection sendSynchronousRequest:urlRequest
                                    returningResponse:&response
                                                error:&error];

    return [[NSString alloc] initWithData:urlData encoding:NSUTF8StringEncoding];
}

+ (id)objectWithUrl:(NSURL *)url {
    SBJSON *jsonParser = [SBJSON new];
    NSString *jsonString = [self stringWithUrl:url];

    return [jsonParser objectWithString:jsonString error:NULL];
}

With these methods you can easily call [YourJSONHelperClass objectWithUrl:yourServiceUrl] which will hand you a NSDictionary in return.

hth
–f

flohei