-1

我有一个 json 文件,代码如下:

{"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 中的访问值是什么。(例如,我想访问文件、文件夹、文件内容、文件夹内容的值)

我不知道。

4

1 回答 1

2

JSON 是一个字典,您可以使用 NSJSONSerialization 将此字符串转换为字典:

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

然后您可以通过键访问属性,以便获取文件夹内容数组:

NSArray *folderContent = [json objectForKey:@"folderContent"];
于 2013-04-20T08:30:12.910 回答