我有以下代码,我希望结尾是 JQuery 自动完成可以读取的 JSON。
[System.Web.Script.Services.ScriptMethod()]
[System.Web.Services.WebMethod]
public static string GetNames(string prefixText, int count)
{
Trie ArtistTrie = (Trie)HttpContext.Current.Cache["CustomersTrie"];
List<string> list = ArtistTrie.GetCompletionList(prefixText, 10);
Dictionary<string, string> dic = new Dictionary<string, string>();
foreach (string a in list)
{
dic.Add(a, "name");
}
string json = JsonConvert.SerializeObject(dic, Formatting.Indented);
return json;
}
JSON 看起来像这样:
{
"the album leaf": "name",
"the all-american rejects": "name",
"the allman brothers band": "name",
"the animals": "name",
"the antlers": "name",
"the asteroids galaxy tour": "name",
"the avett brothers": "name",
"the band": "name",
"the beach boys": "name",
"the beatles": "name"
}
这是倒退,我想要
"name" : "the allman brothers"
但是....字典需要一个唯一的键,相同的值是可以的,
对此有什么简单的解决方法,这也可以从 JQuery 中读取吗?