JsonConvert.SerializeObject添加默认结果名称



每当我试图用JsonConvert序列化对象时。SerializeObject它添加了一个默认的数组名"d"

        json = JsonConvert.SerializeObject(new
        {
            resultsets = new List<Result>()
                {
                    new Result { id = 1, value = "ABC", info = "ABC" },
                    new Result { id = 2, value = "JKL", info = "JKL" },
                    new Result { id = 3, value = "GSG", info = "DYU" }
                }
        });
        return json;
Json响应是
{
   "d": "{"resultsets":[{"id":1,"value":"ABC","info":"ABC"},{"id":2,"value":"JKL","info":"JKL"},{"id":3,"value":"GSG","info":"DYU"}]}"
}

我想要一个简单的数组如下

{"resultsets":[{"id":1,"value":"ABC","info":"ABC"},{"id":2,"value":"JKL","info":"JKL"},{"id":3,"value":"GSG","info":"DYU"}]}

这是为了防止直接执行脚本:

假设您返回的是一个普通数组。以下不是有效的js语句:

{"d": [1]}

而这是:

[1]

你可以在这里找到更多信息:

http://encosia.com/a-breaking-change-between-versions-of-aspnet-ajax/评论- 34045

相关内容

  • 没有找到相关文章