예제 #1
0
        public AnalyzeJson(string json)
        {
            val = json;
            if (json == null)
            {
                return;
            }
            //if (json.IndexOf("\\\"") != -1)
            //    json = json.Replace("\\\"", "\"");
            //if (json.IndexOf("\"{") != -1)
            //    json = json.Replace("\"{", "{");
            //if (json.IndexOf("\"}") != -1)
            //    json = json.Replace("}\"", "}");

            try
            {
                if (json[0] == '[')
                {
                    handleArray(json);
                    return;
                }

                int length = json.Length;

                for (int i = 0; i < length; i++)
                {
                    bool isNext = false;
                    //跳过开头
                    while (i < length && json[i++] != '"')
                    {
                        ;
                    }
                    //读名称
                    while (i < length && json[i] != '"')
                    {
                        key.Append(json[i++]);
                    }
                    while (i < length && json[i++] != ':')
                    {
                        ;
                    }
                    //读内容
                    while (i < length && json[i] != '"' && json[i] != '[' && json[i] != '{')
                    {
                        //null
                        if (json[i] == 'n' &&
                            json[i + 1] == 'u' &&
                            json[i + 2] == 'l' &&
                            json[i + 3] == 'l')
                        {
                            dic.Add(key.ToString(), null);
                            key.Clear();
                            value.Clear();
                            i     += 3;
                            isNext = true;
                            break;
                        }
                        //bool
                        else if (json[i] == 't' &&
                                 json[i + 1] == 'r' &&
                                 json[i + 2] == 'u' &&
                                 json[i + 3] == 'e')
                        {
                            dic.Add(key.ToString(), new AnalyzeJson("true"));
                            key.Clear();
                            value.Clear();
                            i     += 3;
                            isNext = true;
                            break;
                        }
                        //bool
                        else if (json[i] == 'f' &&
                                 json[i + 1] == 'a' &&
                                 json[i + 2] == 'l' &&
                                 json[i + 3] == 's' &&
                                 json[i + 4] == 'e')
                        {
                            dic.Add(key.ToString(), new AnalyzeJson("false"));
                            key.Clear();
                            value.Clear();
                            i     += 4;
                            isNext = true;
                            break;
                        }
                        //数值
                        if (json[i] >= '0' && json[i] <= '9')
                        {
                            while (json[i] != ',' && json[i] != '}')
                            {
                                value.Append(json[i++]);
                            }
                            i--;
                            dic.Add(key.ToString(), new AnalyzeJson(value.ToString().Trim()));
                            key.Clear();
                            value.Clear();
                            isNext = true;
                            break;
                        }
                        ///////////////////////////////////////////////////////////
                        i++;
                    }
                    if (isNext)
                    {
                        continue;
                    }
                    i++;
                    if (i - 1 > length || i > length)
                    {
                        return;
                    }
                    if (json[i - 1] == '"')
                    {
                        int endI = findEnd(json, i - 1);

                        //while (i < length && json[i] != '"')
                        //    value.Append(json[i++]);
                        while (i < endI)
                        {
                            value.Append(json[i++]);
                        }
                        dic.Add(key.ToString(), new AnalyzeJson(value.ToString(), true));
                        key.Clear();
                        value.Clear();
                    }
                    else if (json[i - 1] == '{')
                    {
                        value.Append("{");
                        while (
                            (i < length && json[i] != '}' && isStart == false) ||
                            (i < length && json[i] == '}' && isStart == false && big != 0) ||
                            (i < length && isStart))
                        {
                            if (isStart == false && json[i] == '{')
                            {
                                big++;
                            }
                            if (isStart == false && json[i] == '}')
                            {
                                big--;
                            }
                            value.Append(json[i++]);
                        }
                        value.Append("}");
                        AnalyzeJson mj = new AnalyzeJson(value.ToString());
                        value.Clear();
                        dic.Add(key.ToString(), mj);
                        key.Clear();
                        value.Clear();
                    }
                    else
                    {
                        value.Append("[");
                        while (
                            (i < length && json[i] != ']' && isStart == false) ||
                            (i < length && json[i] == ']' && isStart == false && middle != 0) ||
                            (i < length && isStart))
                        {
                            if (isStart == false && json[i] == '[')
                            {
                                middle++;
                            }
                            if (isStart == false && json[i] == ']')
                            {
                                middle--;
                            }
                            value.Append(json[i++]);
                        }
                        value.Append("]");
                        AnalyzeJson mj = new AnalyzeJson(value.ToString());
                        value.Clear();
                        dic.Add(key.ToString(), mj);
                        key.Clear();
                        value.Clear();
                    }
                }
            }
            catch (Exception e)
            {
                error = e.ToString();
            }
        }
예제 #2
0
        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);
            }
        }