JSON硬编码数据C#

JSON硬编码数据C#,c#,arrays,json,C#,Arrays,Json,我正在C#中手动创建JSON数据。我需要返回JSON结果的数组。我想像下面那样返回数组,但我不想得到文本 publicjsonresult GetFruits() { 返回Json(新的 { 水果=新列表 { 新的{ Color=“红色”, Name=“苹果”, Shape=“圆形” } } },JsonRequestBehavior.AllowGet); }@JimmyFL已经给出了答案 我发现了不同的方法 public JsonResult GetFruits() {

我正在C#中手动创建JSON数据。我需要返回JSON结果的数组。我想像下面那样返回数组,但我不想得到文本

publicjsonresult GetFruits()
{
返回Json(新的
{
水果=新列表
{
新的{
Color=“红色”,
Name=“苹果”,
Shape=“圆形”
}
}
},JsonRequestBehavior.AllowGet);

}
@JimmyFL已经给出了答案

我发现了不同的方法

 public JsonResult GetFruits()
    {
        return Json(new List<object>
        {
            new {
                    Color="Red",
                    Name="Apple",
                    Shape="Round"
                }
        }, JsonRequestBehavior.AllowGet);
    }
publicjsonresult GetFruits()
{
返回Json(新列表
{
新的{
Color=“红色”,
Name=“苹果”,
Shape=“圆形”
}
},JsonRequestBehavior.AllowGet);
}

@Balaji那么,如果您不想在JSON输出中使用
Fruits
属性,为什么要使用它呢?
public JsonResult GetFruits()
{
    var fruits = new List<Fruit>
    {
        new Fruit 
        {
            Color = "Red",
            Name = "Apple",
            Shape = "Round"
        },
        new Fruit 
        {
            Color = "Green",
            Name = "Melon",
            Shape = "Square"
        }
    };

    return Json(fruits, JsonRequestBehavior.AllowGet);
}             
 public JsonResult GetFruits()
    {
        return Json(new List<object>
        {
            new {
                    Color="Red",
                    Name="Apple",
                    Shape="Round"
                }
        }, JsonRequestBehavior.AllowGet);
    }