Pergunta

i'm trying to follow this tutorial here http://ios-blog.co.uk/iphone-development-tutorials/parsing-json-on-ios-with-asihttprequest-and-sbjson/ to do both the ASIHttp and SBJSon tutorial at the same time and all is well until the line

NSMutableArray *colorTitles = [jsonDictionary objectForKey:@"title"];

where it would crash with the error

Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSArrayM objectForKey:]: unrecognized selector sent to instance 0x9340d20'

i've tried using NSArray, NSString and am running out of ideas... my codes are exavtly the same with the link

Foi útil?

Solução

This Probably happens when you try Call the method which don't belong corresponding Class or it superClass then in this case you get error:unrecognized selector sent to instance.

So Check what JSON you getting. According to the JSON Response(data)try to parse it.

I'd like to tell you about the JSON:

JSON is built on two structures:

A collection of name/value pairs. In various languages, this is realized as an object, record, struct, dictionary, hash table, keyed list, or associative array.
An ordered list of values. In most languages, this is realized as an array, vector, list, or sequence.

In JSON, they take on these forms:

Object

An object is an unordered set of name/value pairs. An object begins with { (left brace) and ends with } (right brace). Each name is followed by : (colon) and the name/value pairs are separated by , (comma).

Array:

An array is an ordered collection of values. An array begins with [ (left bracket) and ends with ] (right bracket). Values are separated by , (comma).

Value

A value can be a string in double quotes, or a number, or true or false or null, or an object or an array. These structures can be nested.

I think you are getting the Value JSON, so Try below. and one thing you can not assign(create object) the value to NSmutableArray Literally. so Please do in below Manner.

NSArray *colorTitles = [jsonDictionary valueForKey:@"title"];

If you still don't get the Proper result.

http://www.json.org/

Outras dicas

objectForKey is a method of NSDictionary, not NSArray. You are probably missing (or overdoing) a step in the JSON string parsing.

Usually, this kind of error comes when you are trying to access a dealloc'd object. Check if you are over-releasing or not retaining the jsonDictionary.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top