I need to map a folder structure which follows a similar pattern as used by Dropbox. As the user navigates up a tree the REST server returns additional JSON data which needs to be mapped using Restkit to Core Data. My JSON is as follows:
{
"object_id": "19BEB55D78EA431EA555CA7ADD72DCA6",
"class": "sfaccount",
"files": [
{
"file_id": "78234782437892438792487942",
"bytes": 0,
"created": "2012-11-12T03:42:55.0000000",
"modified": "2012-11-12T03:42:55.0000000",
"path": "/",
"is_dir": true,
"contents": [
{
"file_id": "980234890234890234980234890",
"name": "file1.xls",
"created": "2012-11-12T03: 42: 55.0000000",
"modified": "2012-11-12T03: 42: 55.0000000",
"path": "/file1.xls",
"is_dir": false,
"mime_type": "text/xls",
"bytes": 78810
},
{
"file_id": "924384238903429802439802890",
"name": "file2.pdf",
"created": "2012-11-12T03: 42: 55.0000000",
"modified": "2012-11-12T03: 42: 55.0000000",
"path": "/file2.pdf",
"is_dir": false,
"mime_type": "text/pdf",
"bytes": 15350
},
{
"file_id": "980349082498024390832490249",
"name": "sub folder 1",
"created": "2012-11-12T03: 42: 55.0000000",
"modified": "2012-11-12T03: 42: 55.0000000",
"path": "/sub folder 1",
"is_dir": true,
"bytes": 0
}
]
}
]
};
If the user navigates up to ‘sub folder 1’, the JSON would be:
{
"object_id": "19BEB55D78EA431EA555CA7ADD72DCA6",
"class": "sfaccount",
"files": [
{
"file_id": "980349082498024390832490249",
"name": "sub folder 1",
"created": "2012-11-12T03: 42: 55.0000000",
"modified": "2012-11-12T03: 42: 55.0000000",
"path": "/sub folder 1",
"is_dir": true,
"bytes": 0,
"contents": [
{
"file_id": "564765785685856856658567575",
"name": "file1.xls",
"created": "2012-11-12T03: 42: 55.0000000",
"modified": "2012-11-12T03: 42: 55.0000000",
"path": "/sub folder 1/file1.xls",
"is_dir": false,
"mime_type": "text/xls",
"bytes": 78810
},
{
"file_id": "345687656675856790676786789",
"name": "file2.pdf",
"created": "2012-11-12T03: 42: 55.0000000",
"modified": "2012-11-12T03: 42: 55.0000000",
"path": "/sub folder 1/file2.pdf",
"is_dir": false,
"mime_type": "text/pdf",
"bytes": 15350
},
{
"file_id": "434546785689689667679988698",
"name": "sub folder 2",
"created": "2012-11-12T03: 42: 55.0000000",
"modified": "2012-11-12T03: 42: 55.0000000",
"path": "/sub folder 1/sub folder 2",
"is_dir": true,
"bytes": 0
}
]
}
]
}
I’m unsure about the model structure and how to create the mapping with Restkit.
This is the object mapping you would use to map that JSON object. The “contents” property in your FileObject class should be an NSArray and will be populated with an array of FileObjects.