iPhone 应用程序出现 JSON 错误

发布于 2024-10-19 17:43:07 字数 2993 浏览 2 评论 0原文

当我尝试在模拟器上运行应用程序时出现错误。 我已在我的应用程序中复制了 JSON(JSON Framework) 项目,但我的模拟器在编译以下行时崩溃,(我使用的是 iOS 4.2)

- (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) 

i am getting error when i try to run an app on my simulator.
I have copied the JSON(JSON Framework) project in my app but my simulator crashes when it compiles the below lines,(I am using iOS 4.2)

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

ERROR:

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) 

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

倾其所爱 2024-10-26 17:43:07

尝试将 -ObjC -all_load 添加到 OTHER_LINKER_FLAGS 设置。如果这不是一个选项,您可以尝试直接使用 SBJsonParser 或 SBJsonWriter 对象而不是类别方法。

Try adding -ObjC -all_load to the OTHER_LINKER_FLAGS setting. If that is not an option, you could try to use the SBJsonParser or SBJsonWriter objects directly rather than the category methods.

一曲琵琶半遮面シ 2024-10-26 17:43:07

确保正在编译 SBJSON 文件!
目标->构建阶段->编译文件<-检查SBJSON的*.m文件是否存在!

Make sure that SBJSON files are being compiled!
Target->Build phases->Compile files <- check if the *.m files of SBJSON are there!

寄意 2024-10-26 17:43:07

将 -ObjC -all_load 添加到应用程序目标 -> 构建设置 -> 链接 -> 其他链接器标志 ->调试在 XCode 4 中有效。

早些时候它崩溃了

Adding -ObjC -all_load to app target->build settings ->Linking ->Other Linker Flags -> Debug worked in XCode 4.

Earlier it was crashing

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文