1

I am trying to show a HTML String in uiwebview and it give me the error below:

 **-[__NSArrayI dataUsingEncoding:]: unrecognized selector sent to instance 0x75caf40
2013-09-17 10:26:48.774 iphoneApp[9395:2903] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSArrayI dataUsingEncoding:]: unrecognized selector sent to instance 0x75caf40'
*** First throw call stack:
(0x1cca012 0x1107e7e 0x1d554bd 0x1cb9bbc 0x1cb994e 0x26fc8ea 0x26fc97a 0x2027fa 0x35a2548 0x1c4df3f 0x1c4da39 0x1c70734 0x1c6ff44 0x1c6fe1b 0x35a1c50 0x9628f5b7 0x96279d4e)
libc++abi.dylib: terminate called throwing an exception*
*emphasized text**

here is the code:

NSString *json = [NSJSONSerialization JSONObjectWithData:data options:kNilOptions error:&error];
NSString *desc = [json valueForKey:@"description"];
NSLog(@"%@",desc);
[self.jobdescription loadHTMLString:desc baseURL:nil];

if I copy the output string from NSLog and put it in loadHTMLString its fine but if I put "desc" which is the same I will get the error. I have not idea what could have gone wrong. Thanks

3
  • 1
    Check structure of data you get - from error message follows that value for key "description" is array, not string Commented Sep 17, 2013 at 15:41
  • but how is it possible. I am getting json data as string and save the value for key in NSString. I dont even have Array in there ? here is the value for key "description" that I get from nslog:"<p style=\"text-align: center;\"><strong>Arizona </strong><br /><strong>Academic Family Medicine</strong><br />One Million+ Metro Population<br /><br /></p><p>Our beautiful Southwest" Commented Sep 17, 2013 at 15:53
  • It is hard to say why without seeing all your code and all your data. Try to check what type desc object actually has Commented Sep 17, 2013 at 15:58

2 Answers 2

1

Try the following statement.

[self.jobdescription loadHTMLString:[NSString stringWithFormat:@"%@",desc] baseURL:nil];

And please check whether the "self.jobdescription" is a UIWebView object or not.

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

5 Comments

Thanks Satya, it shows the String in the UIWebView but with parentheses and double quotes, is there any way I can eliminate them ?
Is it displaying those quotes & parentheses while directly loading with out using "desc" variable?
I just copied the code that you sent and it shows them !! also, Yakymiv says that desc might be an array. He is right. I change my code to: NSString *desc = [json valueForKey:@"description"]; NSString *myArrayString = [desc description]; //NSLog(@"%@",myArrayString); // NSLog(@"%@", NSStringFromClass([myArrayString class])); [self.jobdescription loadHTMLString:myArrayString baseURL:nil]; it shows the string just fine but with parentheses !!!
then do this, replace the parentheses with empty strings. Like myArrayString = [myArrayString stringByReplacingOccurrencesOfString:@"(" withString:@""]; same for right parentheses also
Got it. Thanks so much. Here is my code for reference:NSString *json = [NSJSONSerialization JSONObjectWithData:data options:kNilOptions error:&error]; NSString *desc = [json valueForKey:@"description"]; NSString *myArrayString = [desc description]; NSString *myArrayString2 = [[myArrayString stringByReplacingOccurrencesOfString:@")" withString:@""] stringByReplacingOccurrencesOfString:@"(" withString:@""]; [self.jobdescription loadHTMLString:myArrayString2 baseURL:nil];
0

Seems like desc is not string but array. Add NSLog(@"%@", NSStringFromClass([desc class])); to ensure.

1 Comment

Yes seems like it is array. this is the out put: 2013-09-17 11:08:54.226 iphoneApp[9563:c07] __NSArrayI . what should I do then ?

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.