附加数组NSDictionary时出错

时间:2014-02-25 09:41:30

标签: ios objective-c arrays

我试图将JSON数据添加到数组中。下面是代码......我不知道我哪里错了..

当我为arrayJSON保留一个Log时,结果如下:

Array Result: [{"ID_PROJECT":1,"NM_PROJECT":"TED"},{"ID_PROJECT":2,"NM_PROJECT":"DL"},{"ID_PROJECT":3,"NM_PROJECT":"PERD"},{"ID_PROJECT":4,"NM_PROJECT":"EPRS "},{"ID_PROJECT":5,"NM_PROJECT":"MSCS"}]

NSArray *arrayJSON = [NSJSONSerialization JSONObjectWithData:urlData
                                                             options:NSJSONReadingAllowFragments
                                                               error:&error];

        NSMutableArray *arrayResult = [NSMutableArray array];

        for(NSDictionary *dictJSON in arrayJSON){

            [arrayResult addObject: [dictJSON objectForKey:@"NM_PROJECT"]];
        }

        NSLog(@"Array Result: %@", arrayResult);

以下是错误代码:

  

014-02-25 15:07:40.602 Demologin [1146:c07] *终止应用程序   未捕获的异常'NSInvalidArgumentException',原因:   ' - [__ NSCFString countByEnumeratingWithState:objects:count:]:   无法识别的选择器发送到实例0x715f430'   * 第一次抛出调用堆栈:(0x1ca3012 0x114fe7e 0x1d2e4bd 0x1c92bbc 0x1c9294e 0xad28 0x1061c7 0x106232 0x553d5 0x5576f 0x55905 0x5e917   0x2296c 0x2394b 0x34cb5 0x35beb 0x27698 0x1bfedf9 0x1bfead0 0x1c18bf5   0x1c18962 0x1c49bb6 0x1c48f44 0x1c48e1b 0x2317a 0x24ffc 0x26ad 0x25d5)   libc ++ abi.dylib:terminate调用抛出异常

1 个答案:

答案 0 :(得分:1)

Array Result: [{"ID_PROJECT":1,"NM_PROJECT":"TED"},{"ID_PROJECT":2,"NM_PROJECT":"DL"},{"ID_PROJECT":3,"NM_PROJECT":"PERD"},{"ID_PROJECT":4,"NM_PROJECT":"EPRS "},{"ID_PROJECT":5,"NM_PROJECT":"MSCS"}]

NSMutableArray *array = [Array Result JSONValue];
[array retain];


NSLog(@"Array Result: %@", array);