我有一个RESTful Web服务(JSON),该服务接受一串单词并输入在一个键值对中分开的所有单词。我想将一个单词放入其自己的键值对
我尝试仅使用Dictionary<String, Int32>
,但它不存储重复项,但最终将每个单词放入其自己的键值对中。我尝试过Dictionary<String, List<Int32>>
,但是将所有单词存储在一个键值对中。 List<KeyValuePair<String,Int32>>
也是如此。
inputLine = inputLine.Replace(" ", "+").Replace("\n","+").Replace("\r","");
TaskTracker(inputLine);
....
public Dictionary<String, List<int>> Map(string inputLine){
Dictionary<String, List<int>> knv = new Dictionary<String, List<int>>();
//interpret the incoming line as a string array, each index are a word
string[] words = inputLine.Split('+');
foreach (string word in words){
//output key assignment with value (KEY,VALUE)
var entry = new List<int>();
entry.Add(1);
knv.Add(word, entry);
}
return knv;
}
目前这里没有重复项,但仍应将每个单词分成其自己的键值对。
[{“ Key”:“大师在他的树上看到一个苹果,他爬上了高干的鱼苗,害羞的风筝,打了节节食,暴动了,买到了它,希望坡绳的范围像涂料一样。空域火场碎石干燥机“,”值“:[1]}]