Example #1
0
 public void TestDictToJson()
 {
     Dictionary<string, int> dict = new Dictionary<string, int>();
     dict["one"] = 1;
     dict["two"] = 2;
     var str = dict.ToJsonString();
     Assert.AreEqual("{\"one\":1,\"two\":2}", str);
 }
Example #2
0
 public ActionResult Test01()
 {
     Dictionary<string,string>dict = new Dictionary<string, string>()
     {
         {"abc","fs"},
         {"授命","rwef"}
     };
     return Content(dict.ToJsonString());
 }
        private string ConvertArgumentsToJson(IInvocation invocation)
        {
            try
            {
                var parameters = invocation.MethodInvocationTarget.GetParameters();
                if (parameters.IsNullOrEmpty())
                {
                    return "{}";
                }

                var dictionary = new Dictionary<string, object>();
                for (int i = 0; i < parameters.Length; i++)
                {
                    var parameter = parameters[i];
                    var argument = invocation.Arguments[i];
                    dictionary[parameter.Name] = argument;
                }

                return dictionary.ToJsonString(true);
            }
            catch (Exception ex)
            {
                Logger.Warn("Could not serialize arguments for method: " + invocation.MethodInvocationTarget.Name);
                Logger.Warn(ex.ToString(), ex);
                return "{}";
            }
        }