2013-03-19 2 views
1

위의 오류를 해결하는 방법? 'JSONValue'선택기에 대한 알려진 인스턴스 메서드가 없습니다

가 나는 오류를 가지고 자동 참조 계산 문제는

NSDictionary *googleResponse = [[NSString stringWithContentsOfURL: [NSURL URLWithString: req] encoding: NSUTF8StringEncoding error: NULL] JSONValue]; 

라인에서 구글지도 API를

- (CLLocationCoordinate2D) geoCodeUsingAddress:(NSString *)address 
{ 
    double latitude = 0.0; 
    double longitude = 0.0; 

    NSString *esc_addr = [address stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]; 
    NSString *req = [NSString stringWithFormat:@"http://maps.google.com/maps/api/geocode/json?sensor=false&address=%@", esc_addr]; 

    NSDictionary *googleResponse = [[NSString stringWithContentsOfURL: [NSURL URLWithString: req] encoding: NSUTF8StringEncoding error: NULL] JSONValue]; 

    NSDictionary *resultsDict = [googleResponse valueForKey: @"results"]; // get the results dictionary 
    NSDictionary *geometryDict = [resultsDict valueForKey: @"geometry"]; // geometry dictionary within the results dictionary 
    NSDictionary *locationDict = [geometryDict valueForKey: @"location"]; // location dictionary within the geometry dictionary 

    NSArray *latArray = [locationDict valueForKey: @"lat"]; 
    NSString *latString = [latArray lastObject];  // (one element) array entries provided by the json parser 

    NSArray *lngArray = [locationDict valueForKey: @"lng"]; 
    NSString *lngString = [lngArray lastObject];  // (one element) array entries provided by the json parser 

CLLocationCoordinate2D location; 
location.latitude = [latString doubleValue];// latitude; 
location.longitude = [lngString doubleValue]; //longitude; 

    return location; 
} 

를 사용하여 주소 문자열에서 latlong를 얻기 위해 아래의 코드를 사용하지 : 알려진 바 없음을 선택기 'JSONValue'에 대한 인스턴스 메서드

내 프로젝트는 ARC를 사용합니다.

어떻게 해결할 수 있습니까?

+0

"XXXJSON.h"를 꺼 냈습니까? –

+0

http://stackoverflow.com/questions/9762432/get-values-from-json-string-objective-c – Bigood

답변

3

JSONValueNSString 위에 추가 된 범주에서 비롯됩니다. 카테고리를 통해 추가 된 메소드를 사용하려면 해당 헤더를 포함시켜야합니다. 이 경우, 누락 된 헤더는

다음 단계를 수행

#import <SBJson/SBJson.h> 
+0

물론 빌드에 해당 .m 파일이 있어야합니다. –

2

NSString에는 JSONValue이라는 메서드가 없습니다 (왜 그런 것으로 추정 했습니까?). 아마도 NSJSONSerialization 클래스를 사용하여 문자열을 NSDictionary 및/또는 NSArray 데이터 구조로 구문 분석해야합니다.

+0

이해가 안 돼요, pls 내가 뭘해야 언급? – NAZIK

+0

@NAZIK 설명서를 읽어야합니다. –

+1

*** downvote를 설명하십시오. *** (어느 쪽이 잘못 되었습니까? **이 대답은 기술적으로 올바르므로. –

1

나는이 문제를 겪었 ... 아마 ..

1) phases-> 컴파일 소스 빌드로 이동합니다.

2) JSON과 관련된 모든 파일에 대해 -fno-objc-arc 플래그를 설정하십시오.

3) 프로젝트를 지우고 다시 빌드하십시오.

이 오류는 ARC로 인해 발생합니다 .. ARC와 함께 작업하는 동안 JSON 키트에는 자동 출시 기능이 있습니다 .. 어쨌든이 도구가 도움이되기를 바랍니다. Good Luck !!

1

악명 높은 SBJson 라이브러리가 필요합니다.

[[NSString stringWithContentsOfURL: [NSURL URLWithString: req] encoding: NSUTF8StringEncoding error: NULL] JSONValue]; 

에는 SBJson 라이브러리에있는 NSString 범주가 필요합니다.

해당 클래스의 호를 비활성화하는 것을 잊지 마십시오.

관련 문제