public JsonResult Analyse() { if (Request.Files.Count == 0) return null; var file = Request.Files[0]; if (file == null) return null; if (file.ContentLength == 0) return null; ITextStatisticBuilder builder = new TextStatisticsBuilder(); var stats = builder.Build(file.InputStream); LightWeightObject lightWeight = stats.ToLightWeight(); var user = Session["user"] as User; if (user != null) { AddLightObjToDb(lightWeight, user, file.FileName); } var words = lightWeight.WordFrequencyDictionary .Take(CountToSerialize) .ToDictionary(pair => pair.Key, pair => pair.Value); var serializer = new JsonSerializerForJit(); string serrialized = serializer.Serialize(words); JsonResult result = Json(serrialized, JsonRequestBehavior.AllowGet); return result; }
public void Serialize_SmallDictionary_NotNullOrEmpty() { IDictionary<string,int> dictionary = new Dictionary<string, int>(); dictionary.Add(new KeyValuePair<string, int> ("Cat",1)); dictionary.Add(new KeyValuePair<string, int>("Dog", 2)); dictionary.Add(new KeyValuePair<string, int>("Rabbit", 3)); var serrializer = new JsonSerializerForJit(); string json = serrializer.Serialize(dictionary); Assert.IsNotNullOrEmpty(json); }
private JsonResult CreateJsonResult(IDictionary<string, int> words) { var serializer = new JsonSerializerForJit(); string serrialized = serializer.Serialize(words); JsonResult result = Json(serrialized, JsonRequestBehavior.AllowGet); return result; }