2011-03-02 1 views
3

Je reçois une erreur lorsque j'essaie d'exécuter une application sur mon simulateur. J'ai copié le projet JSON (cadre JSON) dans mon application, mais plantage de mon simulateur quand il compile les lignes ci-dessous, (je suis en utilisant iOS 4,2)Erreur JSON sur l'application iPhone

- (void)viewDidLoad { 
    [super viewDidLoad]; 
    NSString *jsonString = [NSString stringWithString:@"{\"foo\": \"bar\"}"]; 
    NSDictionary *dictionary = [jsonString JSONValue]; 
    NSLog(@"Dictionary value for \"foo\" is \"%@\"", [dictionary objectForKey:@"foo"]); 
} 

ERREUR:

2011-03-02 13:33:37.304 test[10918:207] -[NSCFString JSONValue]: unrecognized selector sent to instance 0x3034 
2011-03-02 13:33:37.308 test[10918:207] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[NSCFString JSONValue]: unrecognized selector sent to instance 0x3034' 
*** Call stack at first throw: 
(
    0 CoreFoundation      0x00da7be9 __exceptionPreprocess + 185 
    1 libobjc.A.dylib      0x00efc5c2 objc_exception_throw + 47 
    2 CoreFoundation      0x00da96fb -[NSObject(NSObject) doesNotRecognizeSelector:] + 187 
    3 CoreFoundation      0x00d19366 ___forwarding___ + 966 
    4 CoreFoundation      0x00d18f22 _CF_forwarding_prep_0 + 50 
    5 test        0x000025d7 -[testViewController viewDidLoad] + 119 
    6 UIKit        0x0035e65e -[UIViewController view] + 179 
    7 test        0x0000237e -[testAppDelegate application:didFinishLaunchingWithOptions:] + 79 
    8 UIKit        0x002b11fa -[UIApplication _callInitializationDelegatesForURL:payload:suspended:] + 1163 
    9 UIKit        0x002b355e -[UIApplication _runWithURL:payload:launchOrientation:statusBarStyle:statusBarHidden:] + 439 
    10 UIKit        0x002bddb2 -[UIApplication handleEvent:withNewEvent:] + 1533 
    11 UIKit        0x002b6202 -[UIApplication sendEvent:] + 71 
    12 UIKit        0x002bb732 _UIApplicationHandleEvent + 7576 
    13 GraphicsServices     0x016dda36 PurpleEventCallback + 1550 
    14 CoreFoundation      0x00d89064 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION__ + 52 
    15 CoreFoundation      0x00ce96f7 __CFRunLoopDoSource1 + 215 
    16 CoreFoundation      0x00ce6983 __CFRunLoopRun + 979 
    17 CoreFoundation      0x00ce6240 CFRunLoopRunSpecific + 208 
    18 CoreFoundation      0x00ce6161 CFRunLoopRunInMode + 97 
    19 UIKit        0x002b2fa8 -[UIApplication _run] + 636 
    20 UIKit        0x002bf42e UIApplicationMain + 1160 
    21 test        0x0000230c main + 102 
    22 test        0x0000229d start + 53 
) 
terminate called after throwing an instance of 'NSException' 
Program received signal: “SIGABRT”. 
(gdb) 
+0

Quel framework JSON utilisez-vous? L'importez-vous dans les classes qui le nécessitent? Vous essayez d'envoyer 'JSONValue' à' NSString', qui n'a pas cette méthode, bien que je suppose que ce framework pourrait utiliser des catégories pour mettre en gras cette fonctionnalité. –

+0

J'ai effectivement téléchargé le fichier JsoniPhoneSDK.dmg à partir d'Internet. J'ai ajouté le dossier JSON dans mon projet comme suggéré par l'un des tutoriels. Inclus le fichier JSON.h dans mon fichier appController.m. J'utilise le tutoriel ci-dessous pour installer JSON http://mobileorchard.com/tutorial-json-over-http-on-the-iphone/ – developer

+0

Avez-vous coché la case pour copier les fichiers source lorsque vous les avez ajoutés à votre projet? Sinon, et vous avez supprimé l'image disque d'origine, cela pourrait être votre problème. –

Répondre

10

Essayez d'ajouter -ObjC -all_load au paramètre OTHER_LINKER_FLAGS. Si ce n'est pas une option, vous pouvez essayer d'utiliser les objets SBJsonParser ou SBJsonWriter directement plutôt que les méthodes de catégorie.

+0

L'option OTHER_LINKER_FLAGS ne fonctionne pas. Je vais essayer de voir si l'autre fonctionne .. – developer

+2

A travaillé pour moi, merci :) –

+0

@developer, vous devez ajouter * deux * paramètres. –

0

Ajout -ObjC -all_load à l'application Target-> paramètres de construction -> Liens -> Autres drapeaux Linker -> Debug travaillé dans XCode 4.

Auparavant, il plantait

9

Assurez-vous que les fichiers sont SBJSON être compilé! Cible-> Construire les phases-> Compiler les fichiers < - vérifiez si les fichiers * .m de SBJSON sont là!