2013-08-03 1 views
0

JSON 구문 분석기에서 다음 구문을 구문 분석하려고합니다. 몇 가지 방법을 시도했지만 실제 JSON 직렬화 NSJSONSerialization 항상 오류를 throw합니다 (잘 실제로 그것은 NSArray * termArray = [dataDictionary objectForKey : @ "용어"];) throw됩니다하지만 dataDictionary 올바른 응답이 없기 때문에 이유는 . 그래서 나는 방황하는 이유, URL 요청이 작동하는 것 같다으로JSON 구문 분석기에서 결과를 인식 할 수 없습니다.

'NSInvalidArgumentException', 이유는. '- [__ NSCFArray objectForKey :] : 인식 할 수없는 선택기 인스턴스에 전송

[ 
{ 
    "id": 20765985, 
    "url": "http://quizlet.com/20765985/basic-portuguese-flash-cards/", 
    "title": "Basic Portuguese", 
    "created_by": "aUser", 
    "term_count": 4, 
    "created_date": 1362858462, 
    "modified_date": 1362858462, 
    "has_images": false, 
    "subjects": [ 
     "Portuguese" 
    ], 
    "visibility": "only_me", 
    "editable": "only_me", 
    "has_access": true, 
    "description": "", 
    "has_discussion": true, 
    "lang_terms": "pt", 
    "lang_definitions": "en", 
    "creator": { 
     "username": "aUser", 
     "account_type": "free", 
     "profile_image": "https://quizlet.com/a/i/animals/38.ndeQ.jpg", 
     "id": 6602337 
    }, 
    "terms": [ 
     { 
      "id": 696519541, 
      "term": "mesa", 
      "definition": "table", 
      "image": null 
     }, 
     { 
      "id": 696519542, 
      "term": "amigo", 
      "definition": "friend", 
      "image": null 
     }, 
     { 
      "id": 696519543, 
      "term": "leite", 
      "definition": "milk", 
      "image": null 
     }, 
     { 
      "id": 696519544, 
      "term": "vender", 
      "definition": "sale", 
      "image": null 
     } 
    ], 
    "display_timestamp": "In March 2013" 
} 

]

이것은 즉, JSON 배열을 의미합니다, 당신은 [이 내가 당신의 JSON의 시작에서

NSURL *myURL = [NSURL URLWithString:@"https://api.quizlet.com/2.0/users/<myUser>/sets?access_token=<myAccessToken>&whitespace=1"]; 

NSData *jsonData = [NSData dataWithContentsOfURL:myURL]; 

NSError *error = nil; 

NSDictionary *dataDictionary = [NSJSONSerialization JSONObjectWithData:jsonData options:0 error:&error]; 
NSArray *termArray = [dataDictionary objectForKey:@"term"]; 

답변

0

을 구문 분석하는 데 사용하는 코드입니다. 따라서 사전으로 액세스 할 수 없습니다. 그래서 로그에 배열이 표시되고 예외가 발생합니다.