0

Possible Duplicate:
-[__NSCFDictionary JSONRepresentation]: unrecognized selector sent to instance

I use SBJson ( http://stig.github.com/json-framework/ ) in two of my project. Therefore I downloaded the code and copied it into my first project so that I can do something like this

NSMutableDictionary* dict = [[NSMutableDictionary alloc] init];
[dict setValue:email  forKey:@"email"];
[dict setValue:password forKey:@"password"];
NSString* json = [dict JSONRepresentation];

Now for my second and new project I did the same. I copied all the source files from SBJson into my new project and used the exact same code as above. But now when the program comes to line NSString* json = [dict JSONRepresentation]; I get the following error message:

-[__NSCFDictionary JSONRepresentation]: unrecognized selector sent to instance 0x689c710

What am I doing wrong in my second project?

Community
  • 1
  • 1
toom
  • 12,864
  • 27
  • 89
  • 128
  • Please check this link:http://stackoverflow.com/questions/5537679/nscfdictionary-jsonrepresentation-unrecognized-selector-sent-to-instance – Midhun MP Jul 04 '12 at 19:19
  • Have you imported `SBJson.h`? – Bill Wilson Jul 04 '12 at 19:19
  • I'm sure you're using a static library but somehow the linker doesn't incorporate the category files SBJson adds to NSDictionary. –  Jul 04 '12 at 19:20
  • 1
    @BillWilson **That doesn't make a difference.** This is a runtime error, not a compiler warning. Obj-C is a dynamic language; importing headers is just for fooling the compiler, the method name lookup occurs at runtime. –  Jul 04 '12 at 19:21
  • @H2C03 I didn't see mention of the static library, sounds like all of the source is included in his project. In any case it could be that all the files have been added to the project but not included in the target. perhaps? – Bill Wilson Jul 04 '12 at 19:25
  • Thank you for your answers. Bill was right: The file have not been automatically added to the target. I do not know why this happened. @Bill give an answer an I will checkmark it as solved. – toom Jul 04 '12 at 19:40
  • No, it's also unrelated to the fact if you include a header or not. It's related to not having included the implementation files. –  Jul 04 '12 at 19:41
  • Yes, Bill, answer, but not the wrong one. Include my correction. –  Jul 04 '12 at 19:41

2 Answers2

1

Make sure that all the files have been added to the target.

Bill Wilson
  • 954
  • 6
  • 9
0
  1. Since iOS 5 you don't need an external library to use JSON, This tutorial could help you with that.

  2. That error is because you are telling to dict, which is an instance of NSMutableDictionary, to perform a method called JSONRepresentation. dict doesn't know how to do that. I haven't work with that library but I would guess that you need to make an instance of SBJSON parser and then send dict as parameter. I found this and this tutorials, I hope they can help you.

marcos1490
  • 362
  • 3
  • 12