2013-04-20 31 views
-2

有一個JSON文件,該文件是下來代碼:我如何訪問值JSON對象在目標C

{"fileContent":[{"name":"directorffdsgfg","type":"file","ext":"sql","modified":"2013\/04\/11 - 10:00","created":"2013\/04\/11 - 10:00","size":"1577"},{"name":"directory02","type":"file","ext":"sql","modified":"2013\/04\/11 - 12:10","created":"2013\/04\/11 - 12:10","size":"1577"},{"name":"jquery-mousewheel-master","type":"file","ext":"zip","modified":"2013\/04\/11 - 12:10","created":"2013\/04\/11 - 12:10","size":"5213"}],"folderContent":[{"name":"Folder 2","type":"folder","ext":"sql","modified":"2013\/04\/11 - 05:04","created":"2013\/04\/11 - 05:04","size":"1577"},{"name":"Folder 1","type":"folder","ext":"zip","modified":"2013\/04\/15 - 09:08","created":"2013\/04\/15 - 09:08","size":"11867"}],"files":9,"folders":2} 

我想知道,在JSON對象獲得什麼價值。 (例如我想訪問文件,文件夾,fileContent,folderContent的值)

我不知道它。

回答

1

JSON是一本字典,你可以使用NSJSONSerialization這個字符串轉換爲詞典:

NSData *jsonData = [jsonString dataUsingEncoding:NSUTF8StringEncoding]; 
NSDictionary *json = [NSJSONSerialization JSONObjectWithData:jsonData options:0 error:nil]; 

那麼你可以通過鍵來訪問性能,因此要獲得該文件夾的內容陣列:

NSArray *folderContent = [json objectForKey:@"folderContent"];