2011-03-02 117 views
3

我在嘗試在模擬器上運行應用程序時出現錯誤。 我抄JSON(JSON Framework)的項目在我的應用程序,但我的模擬器崩潰時它編譯下面的線,(我使用的是iOS 4.2)iPhone應用程序出現JSON錯誤

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

錯誤:

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

您正在使用哪種JSON框架?你是否在需要它的類中導入它?你試圖發送'JSONValue'到'NSString',它沒有這樣的方法,但我認爲這個框架可以利用類別來加強這個功能。 – 2011-03-02 20:39:41

+0

我已經從網上下載了JsoniPhoneSDK.dmg文件。我按照其中一個教程的建議在我的項目中添加了JSON文件夾。將JSON.h文件包含在我的appController.m文件中。我使用下面的教程來安裝JSON http://mobileorchard.com/tutorial-json-over-http-on-the-iphone/ – developer 2011-03-02 20:48:10

+0

您是否勾選了將源文件添加到項目中時複製源文件的複選框?如果沒有,並且您刪除了原始磁盤映像,則可能是您的問題。 – 2011-03-02 21:12:57

回答

10

嘗試增加-ObjC -all_load設置爲OTHER_LINKER_FLAGS設置。如果這不是一個選項,您可以嘗試直接使用SBJsonParser或SBJsonWriter對象,而不是類別方法。

+0

OTHER_LINKER_FLAGS選項不起作用。我會嘗試看看另一個是否工作.. – developer 2011-03-09 17:23:13

+2

爲我工作,謝謝:) – 2012-04-13 13:23:09

+0

@developer,你需要添加*兩個*設置。 – 2012-04-26 10:07:27

0

添加-ObjC -all_load到App靶>構建設置 - >鏈接 - >其他鏈接標誌 - >調試工作中的XCode 4

此前據崩潰

9

確保SBJSON文件正在編譯! 目標 - >構建階段 - >編譯文件< - 檢查SBJSON的* .m文件是否存在!

相關問題