0

I'm attempting to create an array from parsed JSON. I know that the JSON is parsing correctly because I tested it by outputting the values into the console. I then changed the code to:

// Start parsing the json
SBJsonParser *parser = [[SBJsonParser alloc] init];
NSError *jsonError;
parsedJson = [[parser objectWithString:myRawJson error:&jsonError] copy];

[parser release];

NSDictionary *price = [parsedJson objectForKey:@"prices"];
NSEnumerator *enumerator = [price objectEnumerator];
NSDictionary* item;

while (item = (NSDictionary*)[enumerator nextObject]) {
    NSArray *price_chunk = [[NSArray alloc] arrayWithObjects:[item objectForKey:@"id"],[item objectForKey:@"table"],[item objectForKey:@"table_id"],[item objectForKey:@"value"],nil];
    NSLog(@"Prices ID: %@", [price_chunk objectAtIndex:0]);
    NSLog(@"Prices Table: %@", [price_chunk objectAtIndex:1]);
    NSLog(@"Prices Table ID: %@", [price_chunk objectAtIndex:2]);
    NSLog(@"Prices Value: %@", [price_chunk objectAtIndex:3]);
}

So I'm trying to make the array, and then test the array by outputting the data into the console. The app crashes, and I receive:

2011-09-21 11:36:56.397 vegas_hipster[23496:207] -[__NSPlaceholderArray arrayWithObjects:]: unrecognized selector sent to instance 0x631b820

2011-09-21 11:36:56.399 vegas_hipster[23496:207] * Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSPlaceholderArray arrayWithObjects:]: unrecognized selector sent to instance 0x631b820'

* Call stack at first throw:

(

0   CoreFoundation                      0x01624be9 __exceptionPreprocess + 185
1   libobjc.A.dylib                     0x017795c2 objc_exception_throw + 47
2   CoreFoundation                      0x016266fb -[NSObject(NSObject) doesNotRecognizeSelector:] + 187
3   CoreFoundation                      0x01596366 ___forwarding___ + 966
4   CoreFoundation                      0x01595f22 _CF_forwarding_prep_0 + 50
5   vegas_hipster                       0x0006ec88 -[UpdateViewController update:] + 1433
6   UIKit                               0x003bfa6e -[UIApplication sendAction:to:from:forEvent:] + 119
7   UIKit                               0x0044e1b5 -[UIControl sendAction:to:forEvent:] + 67
8   UIKit                               0x00450647 -[UIControl(Internal) _sendActionsForEvents:withEvent:] + 527
9   UIKit                               0x0044f438 -[UIControl touchesBegan:withEvent:] + 277
10  UIKit                               0x003e4025 -[UIWindow _sendTouchesForEvent:] + 395
11  UIKit                               0x003c537a -[UIApplication sendEvent:] + 447
12  UIKit                               0x003ca732 _UIApplicationHandleEvent + 7576
13  GraphicsServices                    0x01dd2a36 PurpleEventCallback + 1550
14  CoreFoundation                      0x01606064 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION__ + 52
15  CoreFoundation                      0x015666f7 __CFRunLoopDoSource1 + 215
16  CoreFoundation                      0x01563983 __CFRunLoopRun + 979
17  CoreFoundation                      0x01563240 CFRunLoopRunSpecific + 208
18  CoreFoundation                      0x01563161 CFRunLoopRunInMode + 97
19  GraphicsServices                    0x01dd1268 GSEventRunModal + 217
20  GraphicsServices                    0x01dd132d GSEventRun + 115
21  UIKit                               0x003ce42e UIApplicationMain + 1160
22  vegas_hipster                       0x00002330 main + 102
23  vegas_hipster                       0x000022c1 start + 53
24  ???                                 0x00000001 0x0 + 1

)

terminate called after throwing an instance of 'NSException'

Program received signal: “SIGABRT”.

2 Answers 2

1

You need to use initWithObjects: method, not arrayWithObjects.

Sign up to request clarification or add additional context in comments.

1 Comment

That was it. Thanks a million.
1
[[NSArray alloc] arrayWithObjects:...

isn't valid. Try:

[NSArray arrayWithObjects:...

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.