我需要我的响应看起来像这样(对象内的 JSON 数组):
{"files":[
{
"name":"3992wp_ss_20130215_0001.jpg","size":102,"url":"/Files/3992wp_ss_20130215_0001.jpg","thumbnail_url":"","de lete_url":"/Files/3992wp_ss_20130215_0001.jpg","delete_type":"DELETE"
}
]}
但我得到了这个(对象周围的 JSON 数组):
[{"files":
{"name":"3992wp_ss_20130215_0001.jpg","size":102,"url":"/Files/3992wp_ss_20130215_0001.jpg","thumbnail_url":"","delete_url":"/Files/3992wp_ss_20130215_0001.jpg","delete_type":"DELETE"}}
]
这是我的代码:
public IEnumerable<allFiles> Post()
{
// read data
List<DocFile> files = new List<DocFile>();
DocFile file1 = new DocFile();
file1.name = _fileName;
file1.size = _lengh;
file1.url = "/Files/" + _fileName;
file1.thumbnail_url = "";
file1.delete_url = "/Files/" + _fileName;
file1.delete_type = "DELETE";
files.Add(file1);
allFiles fileCont = new allFiles();
fileCont.files = files;
return fileCont;
}
public class allFiles
{
public IEnumerable<DocFile> files { get; set; }
}
public class DocFile
{
public string name { get; set; }
public long size { get; set; }
public string url { get; set; }
public string thumbnail_url { get; set; }
public string delete_url { get; set; }
public string delete_type { get; set; }
}