基于JSON的Mvc 4模型

时间:2014-02-01 23:03:03

标签: json asp.net-mvc-4

我正在编写mVC4应用程序,我想创建一个模型来生成以下JSON文件:

{
"area": {
       "areaid": "1",
       "venueid": "41",
       "fnames": "12",
          "s": [{"Id":1,"V":"0,1,2,2,1,1,1,0B-001,0,0,0,"},
                {"Id":2,"V":"2,1,2,2,1,1,1,0B-001,0,0,0,"},
                {"Id":3,"V":"3,1,2,2,1,1,1,0B-001,0,0,0,"}]
         }
 }

那样的东西?

public class Area
{
    [Key]
    public int areaid { get; set; }
    public int venueid { get; set; }
    public int fnames { get; set; }
    [ForeignKey("Id")]
    public List<Book> s { get; set; }

} 

public class Book
{
    [Key]
    public int Id { get; set; }
    public string V { get; set; }
}

1 个答案:

答案 0 :(得分:0)

我认为这应该有效。以下是使用Visual Studio 2013的粘贴JSON作为类功能...

的结果
public class Rootobject
{
    public Area area { get; set; }
}

public class Area
{
    public string areaid { get; set; }
    public string venueid { get; set; }
    public string fnames { get; set; }
    public List<Book> s { get; set; }
}

public class Book
{
    public int Id { get; set; }
    public string V { get; set; }
}