내가 트위터의 GET 동향의 호출에 의해 반환 된 다음 JSON을 구문 분석 sbjson를 사용할 때 나는 데 문제/이해하려고 노력하고 WOEID :SBJSON는/:
내가 사용하고를 WOEID "http://api.twitter.com/1/trends/1.json"@ 나는 다음과 같은 응답을 얻을 : URL을 다음 여기에
[
{
"trends": [
{
"name": "Premios Juventud",
"url": "http://search.twitter.com/search?q=Premios+Juventud",
"query": "Premios+Juventud"
},
{
"name": "#agoodrelationship",
"url": "http://search.twitter.com/search?q=%23agoodrelationship",
"query": "%23agoodrelationship"
}
],
"as_of": "2010-07-15T22:40:45Z",
"locations": [
{
"name": "Worldwide",
"woeid": 1
}
]
}
]
가 난 코드입니다 (공간을 절약하기 위해립니다) 구문 분석하고 이름과 URL을 표시하는 데 사용 :
NSMutableString *content = [[NSMutableString alloc] initWithBytes:[responseData bytes] length:[responseData length] encoding:NSUTF8StringEncoding];
[content replaceCharactersInRange:NSMakeRange(0, 1) withString:@""];
[content replaceCharactersInRange:NSMakeRange([content length]-1, 1) withString:@""];
NSLog(@"Content is: %@", content);
SBJsonParser *parser = [[SBJsonParser alloc] init];
NSDictionary *json = [parser objectWithString:content];
//NSArray *trends = [json objectForKey:@"trends"];
NSArray *trends = [json objectForKey:@"trends"];
for (NSDictionary *trend in trends)
{
[viewController.names addObject:[trend objectForKey:@"name"]];
[viewController.urls addObject:[trend objectForKey:@"url"]];
}
[parser release];
이 코드는 현재 사용되지 않는 Twitter의 GET 트렌드 호출을 대상으로했기 때문에 깨진 샘플 코드입니다. 이 코드는 수동으로 '['과 last ']를 수동으로 제거하면 작동합니다. 그러나 응답에서 해당 문자를 제거하지 않으면 파서가 NSString 요소 인 NSArray를 NSString 요소 인 json 응답으로 반환합니다.
이 응답을 올바르게 구문 분석해야합니까? 미리 감사드립니다.