开发者

-[__NSArrayI stringByReplacingOccurrencesOfRegex:withString:]: unrecognized selector sent to instance

开发者 https://www.devze.com 2023-02-17 11:05 出处:网络
Im trying to clean up a json stream and get the error listed above N开发者_开发技巧SString *traveladvice = [json valueForKeyPath:@\"travel_advice_article.travel_advice_sections.body.markup\"];

Im trying to clean up a json stream and get the error listed above

N开发者_开发技巧SString *traveladvice = [json valueForKeyPath:@"travel_advice_article.travel_advice_sections.body.markup"];

which gets me a stream with lots of javascript regular expressions like \U00a0 which I want to remove. Im using to regexlite to remove.

NSString *regexString = @"U00a0"; 
NSString *replacementString = @"";
NSString *travelparse1 = nil; 

travelparse1 = [travelAdvice stringByReplacingOccurrencesOfRegex:regexString     
withString:replacementString];  

I understand the error but whats confusing me is that traveladvice is an NSString not an NSArray.


json valueForPath might return an array, not a string. stop in a debugger and do 'po traveladvice' it will show you the actual data.

also, store the result type as 'id' and not NSString* to avoid confusion

0

精彩评论

暂无评论...
验证码 换一张
取 消