2016-03-17 144 views
1

我得到的格式從我的服務器響應這樣的:轉換NSData對象到的NSArray

[_postViolationOperation setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id responseObject) { 
     if (responseObject != nil && [responseObject isKindOfClass:[NSData class]]) { 
      //some code to convert responseObject to NSArray 
      //responseObject looks like this: ["fsdfsf","sdfsfd"] 
     } 

} failure:nil]; 

我怎樣才能將它轉換爲NSArray的?

+1

請分享您的代碼 –

+1

你能提供一些額外的代碼,很容易解決 –

+0

你的問題應該是,「如何解析JSON數據到NSArray?' –

回答

2
NSError *error = nil; 
NSArray *jsonArray = [NSJSONSerialization JSONObjectWithData: responseData options: NSJSONReadingMutableContainers error: &error]; 
+0

這段代碼的目的是什麼? –

2

這裏是代碼轉換NSData對象到的NSArray

NSError *error = nil; //for error 
NSData *dataObject; //put your data in dataObject 
NSArray *ArrayObject = [NSJSONSerialization JSONObjectWithData: dataObject options: NSJSONReadingMutableContainers error: &error]; 
+0

對我來說很好的工作! – Rex