public void add(string key, object val, DataStyle style) { try { switch (style) { case DataStyle.BOOL: dic.Add(key, new MakeJson((bool)val)); break; case DataStyle.STR: case DataStyle.DATE: { string val2 = val.ToString(); if (val2.Contains("\"")) { for (int i = val2.Length - 1; i >= 0; i--) { if ((val2[i] == '\"' && i == 0) || (val2[i] == '\"' && i > 0 && val2[i - 1] != '\\')) { error = "添加了不符合要求的值:" + val2; } } } MakeJson j = new MakeJson(val2.ToString()); dic.Add(key, j); break; } case DataStyle.INT: dic.Add(key, new MakeJson((int)val)); break; case DataStyle.DOUBLE: dic.Add(key, new MakeJson((double)val)); break; case DataStyle.ARRAY: { MakeJson j = new MakeJson(); j.array = (MakeJson[])val; j.style = style; dic.Add(key, j); break; } case DataStyle.DIC: dic.Add(key, (MakeJson)val); break; case DataStyle.NULL: dic.Add(key, new MakeJson(null)); break; case DataStyle.LONG: dic.Add(key, new MakeJson((long)val)); break; default: break; } } catch (Exception e) { if (key != null) { Log.AddLog("Json", "Key:" + key); } if (val != null) { Log.AddLog("Json", "Val:" + val.ToString()); } Log.AddLog("Json", "josn添加节点异常"); error = "josn添加节点异常:" + e.ToString(); } }
async private void ok_Click(object sender, RoutedEventArgs e) { if (p1.Text == "" || p2.Password == "") { if (check != null && check.Status == TaskStatus.Running) { return; } } enable_false(); tip.Visibility = Visibility.Visible; string name = p1.Text; string psw = tools.CommonFunction.GetMD5String(p2.Password); string timeTag = CD.timeTag.updateTag(); string error = null; string src = "正在验证,请稍候..."; Task task = new Task(new Action(() => { int num = 3; while (CD.timeTag.equal(timeTag)) { string tag = src.Substring(0, src.Length - num); Dispatcher.Invoke(System.Windows.Threading.DispatcherPriority.Normal, new Action(() => { tip.Text = tag; })); num--; if (num < 0) { num = 3; } //if (check != null && check.Status == TaskStatus.RanToCompletion) //{ // if (error != null) // { // Dispatcher.Invoke(System.Windows.Threading.DispatcherPriority.Normal, new Action(() => // { // ShowTip.show(false, null, error); // })); // } // return; //} Thread.Sleep(1000); } })); task.Start(); check = new Task(new Action(() => { tools.MakeJson inJson = new tools.MakeJson(); inJson.add("username", name); inJson.add("password", psw.ToUpper()); tools.AnalyzeJson retJson = YTH.Functions.Post.Post_Json("checkAdmin", inJson.ToString()); error = retJson.error; })); check.Start(); await check.ConfigureAwait(true); tip.Visibility = Visibility.Hidden; if (error == null) { if (CD.timeTag.equal(timeTag)) { nextStep(); } } else { enable_true(); CD.timeTag.updateTag(); ShowTip.show(false, null, error); } }