2017-02-06 12 views
1
[manager POST:urlString parameters:[self jsonDict] success:^(AFHTTPRequestOperation *operation, id responseObject){ 

     NSLog(@"response data: %@", responseObject); 


     NSArray *postFromResponse = [ responseObject valueForKeyPath:@"credentials"]; 
    NSLog(@"credentials:%@", postFromResponse); 

     for(NSDictionary *object in postFromResponse) 
     { 
      NSString *AccessKeyId = [object valueForKeyPath:@"AccessKeyId"]; 
      NSLog(@"%@", AccessKeyId); 
     } 



} 

に応答オブジェクトをキャストする方法:それは私にエラーを与える方法を対象

Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[<__NSCFString 0x79ea4430> valueForUndefinedKey:]: this class is not key value coding-compliant for the key AccessKeyId'

+0

'(postFromResponseでNSDictionaryの*オブジェクト)のために': 'postFromResponse'はそう'NSString'オブジェクトだけでなく、' NSString'オブジェクトも(すべてではないにしても) 'NSString'オブジェクトを持つようにします。そのため、 'object'が' NSString'の場合、 'valueForKeyPath'を呼び出すことができません。それとも、 'responseObject'が' NSString'ではなく 'NSDictionary'ですか?どのラインが問題を引き起こしているのかは明らかではなく、JSONが助けてくれることを示しています。 – Larme

+0

私の応答は:credentials = {AccessKeyId = abac; SecretAccessKey = "99"; SessionToken = "rt"; }; – san

+0

あなたの質問を更新(編集)し、 'postFromResponse'や' responseObject'の値であるかどうかを指定してください。 – Larme

答えて

0

はこれを試してみてください:

NSMutableDictionary *responseDict = [NSJSONSerialization JSONObjectWithData:responseObject options:NSJSONReadingMutableContainers error:nil]; 
NSArray *postFromResponse = [responseDict valueforkey:@"credentials"]; 
for(NSDictionary *object in postFromResponse) { 
    NSString *AccessKeyId = [object valueforkey:@"AccessKeyId"]; 
    NSLog(@"%@", AccessKeyId); 
} 
+0

キャッチされていない例外 'NSInvalidArgumentException'のためにアプリケーションを終了しています、理由: ' - [__ NSDictionaryI bytes]:インスタンス0x7a0abc50に送信された認識できないセレクタ' ..sorryそれは私にエラーを与えます: – san

+0

私の応答は:クレデンシャル= { AccessKeyId = abac; SecretAccessKey = "99"; SessionToken = "rt"; }; – san

+0

try nsstring * a = [[responseDict valueforkey:@ "credentials"] valueforkey:@ "AccessKeyId"]; –

関連する問題