My favorites | Sign in
Project Logo
                
Search
for
Updated Jun 23, 2009 by sbrautaset
Labels: Featured, Phase-QA
FAQ  
Frequently Asked Questions

Frequently Asked Questions

My app works in the iPhone simulator, but crashes on the device

The new (3.0) linker apparently has a bug in that -ObjC isn't processed correctly, on device builds only. So if you have a Category in a static library, and try to reference a method in that category, it will work on the simulator, but crash your app in the device.

This occurred when I using the JSON library and calling [foo JSONValue], as well as a few other places that I had category calls.

The solution is to include the linker flag -all_load in addition to -ObjC.

(Thanks to Greg Pasquariello)

I get a "Library not loaded" error when trying to use the framework on the iPhone

Dynamic libraries are not supported on the iPhone. You have to use the custom SDK that ships with recent releases of this framework.

The full error is probably something like this:

Dyld Error Message:
  Library not loaded: @loader_path/../Frameworks/JSON.framework/Versions/A/JSON
  Referenced from: /Users/santthosh/Library/Application Support/iPhone
Simulator/User/Applications/FC6355D7-960A-4E5F-8003-AA36B561C260/HelloNavigation.app/HelloNavigation
  Reason: image not found

The framework fails to parse seemingly-valid JSON

Are you sure it's legal JSON? This framework is really strict, so won't accept stuff that (apparently) several validators accepts. In particular, literal TAB, NEWLINE or CARRIAGE RETURN (and all other control characters) characters in string tokens are disallowed, but can be very difficult to spot. (These characters are allowed between tokens, of course.)

To help debug you may find it handy to use the -objectForString:error: method, and query the returned error object, like so:

    NSError *err;
    if (![json objectWithString:jsonrep error:&err]) {
        while (err) {
            NSLog(@"%@", [err userInfo]);
            err = [[err userInfo] objectForKey:@"NSUnderlyingError"];
    }

Alternatively you could try upgrading to the version in trunk (though you'll have to install from source, as there is no binary package yet) where you can simply do this:

SBJsonParser *parser = [SBJsonParser new];
id object = [parser objectWithString:jsonString];
if (!object)
	NSLog(@"Error trace: %@", parser.errorTrace);

If you get something like the below (the number may vary) then one of your strings has disallowed unicode control characters in it.

    NSLocalizedDescription = "Unescaped control character '0x9'";

Comment by dav.yaginuma, Mar 29, 2009

Note: I was unable to get the JSON.h header recognized, even when dropping the whole framework into my Xcode Frameworks folder. In the end I had to use the instructions on this page to get this framework working: http://iphone.zcentric.com/2008/08/05/install-jsonframewor/

Comment by josh.estelle, Mar 30, 2009

The INSTALL doesn't make it entirely clear that one should use the SDK or the Framework, and not both.

I made the changes to use the SDK and added the Framework, and I got the same "Library not loaded" errors. I then removed the framework, and all was well.

I'm developing on the iPhone. Cheers. Josh

Comment by roocell, Jun 04, 2009

I had a problem with codesign for the project that was using JSON and found the solution here.

http://iphone.galloway.me.uk/2009/04/json-framework-codesign-object-file-format-invalid-or-unsuitable/comment-page-1/#comment-214

you have to edit project settings and change "Code Signing Resource Rules Path"

Comment by matt.long, Jul 24, 2009

Using NSNull for null fields is probably the right approach but the resulting parsed NSDictionary and NSArrays are not able to be serialized with a call to -writeToFile which is very handy if you need to store the data locally. I changed -scanRestOfNull to use an empty string @"" instead of NSNUll to suit my needs, but I'm wondering if there's maybe another way to retain the proper type, NSNull, while being able seriealize/deserialize the objects as plist files.

-Matt

Comment by sbrautaset, Jul 25, 2009

Matt, can you not just write the JSON string directly to disk?

Comment by shayne.oneill, Oct 24, 2009

Does anyone know a good non-strict parser? This thing chokes on a lot of Google JSON.


Sign in to add a comment
Hosted by Google Code