Instance method '-jsonValue'not found (ret

2020-03-30 07:11发布

I got problem in following statement.

 NSArray *feedsData = [strFeedsResponse JSONValue];

6条回答
Anthone
2楼-- · 2020-03-30 07:18

I presume strFeedsResponse is an instance of NSString. There is no such method as JSONValue in NSString. You need NSString category and add the JSONValue method there.

You can use for example SBJson library https://github.com/stig/json-framework/, which contains NSString+SBJson.h header, which adds the JSONValue method for NSString.

This header must be than imported in the source file where you want to use the JSONValue method:

#import NSString+SBJSON.h

More about categories for example here: http://macdevelopertips.com/objective-c/objective-c-categories.html

查看更多
姐就是有狂的资本
3楼-- · 2020-03-30 07:21

Hope this helps future searchers on this error...

The reason for the error is that the current version of SBJson seems to not contain the NSString category "NSString+SBJSON.h" referred to by an earlier poster. So, you could easily write your own, or just use the SBJsonParser class directly ("address" is just an NSString containing something like "24 Elm Street, Yourtown, New Mexico"):

NSString     *esc_addr       = [address stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
NSString     *req            = [NSString stringWithFormat:@"http://maps.google.com/maps/api/geocode/json?sensor=false&address=%@", esc_addr];
NSString     *response       = [NSString stringWithContentsOfURL: [NSURL URLWithString: req] encoding: NSUTF8StringEncoding error: NULL];
SBJsonParser *parser         = [[SBJsonParser alloc] init];
NSDictionary *googleResponse = [parser objectWithString:response];

Cheers!

查看更多
Bombasti
4楼-- · 2020-03-30 07:28

This error generally comes when method not found.Here it comes because JSONValue function is not found.
Please make sure you have included json header files where you calling this function.

查看更多
虎瘦雄心在
5楼-- · 2020-03-30 07:33

If you are using a webservice, then give the URL for that.

try this way...

NSArray* latestentry = (NSDictionary*)[responseString JSONValue];
查看更多
霸刀☆藐视天下
6楼-- · 2020-03-30 07:36
 NSArray *feedsData = [[strFeedsResponse JSONValue] mutableCopy];

Use this Line, it will be useful to you..

查看更多
女痞
7楼-- · 2020-03-30 07:41

One of two things is happening:

  1. strFeedsResponse is not ACTUALLY an instance of an NSString. Maybe it is null or it has been initiated with an incorrect value. You can add a breakpoint to your code to check the value that is stored in strFeedsResponse before you call JSONValue on it.

  2. You have not correctly imported the JSON framework that you are using into your class. You need to add the JSON header to your class.

查看更多
登录 后发表回答