我正在使用TouchJSON。撥打我的Rails應用程序以獲取localhost:3000/posts.json上的所有「帖子」。這將返回一個JSON數組,由方括號包圍。我目前設置爲將jsonString轉換爲NSDictionary,但由於方括號而失敗。如何用TouchJSON解析JSON數組?
NSString *jsonString=[self jsonFromURLString:@"http://localhost:3000/posts.json"];
NSData *jsonData = [jsonString dataUsingEncoding:NSUTF8StringEncoding];
NSError *error = nil;
self.dictionary = [[CJSONDeserializer deserializer] deserializeAsDictionary:jsonData error:&error];
什麼把這個結果轉換使用TouchJSON庫一個NSArray的最佳方式?
Error Domain=kJSONScannerErrorDomain Code=-101 "Could not scan dictionary. Dictionary that does not start with '{' character."
-deserializeAsArray:函數已被棄用我猜是因爲它在TouchJSON代碼中不再可用。但正如JeremyP已經說過的,只是使用-deserialize:函數,它會起作用。 – Leon 2013-02-13 08:53:44