0
我需要我的迴應是這樣的(對象內部的JSON數組):試圖從一個asp.net的Web API得到正確的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; }
}
你得到它!謝謝! – vts 2013-02-28 19:44:23