2015-04-22 71 views
2

我目前正試圖發佈到一個php web服務,它將查詢一個mysql數據庫,並[應]返回一個字符串值。我研究過AFNetworking,但不明白如何使用查詢返回的值。例如:iOS AFNetworking的帖子麻煩

AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager]; 
[manager POST:@"http://samwize.com/api/poo/" 
parameters:@{@"color": @"green"} 
    success:^(AFHTTPRequestOperation *operation, id responseObject) { 
NSLog(@"JSON: %@", responseObject); 
} failure:^(AFHTTPRequestOperation *operation, NSError *error) { 
NSLog(@"Error: %@", error); 
}]; 

我猜我操縱responseObject來得到我期望的字符串?任何幫助,將不勝感激

回答

1
AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager]; 
     [manager POST:@"http://samwize.com/api/poo/" 
      parameters:@{@"color": @"green"} 
       success:^(AFHTTPRequestOperation *operation, id responseObject) { 
        NSError *error = nil; 
        NSDictionary *JSON = [NSJSONSerialization JSONObjectWithData:responseObject options:NSJSONReadingAllowFragments error:&error]; 
        if (error) { 
         NSLog(@"Error serializing %@", error); 
        } 
        NSLog(@"JSON: %@", JSON); 
       } failure:^(AFHTTPRequestOperation *operation, NSError *error) { 
        NSLog(@"Error: %@", error); 
       }]; 

這將您JSON響應轉換成NSDictionary

+0

謝謝。我怎樣才能返回一個給定的密鑰值使用nsdictionary – GregH

+0

我不知道如果我理解你的問題是正確的,你想從一個關鍵的價值?看看這個答案,如果有幫助http://stackoverflow.com/questions/16233425/get-values-of-particular-key-in-nsdictionary – Vig