Example #1
0
        public static List<JSONObjectOLD> GetObjects(string Input)
        {
            List<JSONObjectOLD> output = new List<JSONObjectOLD>();
            StringBuilder buffer = new StringBuilder();

            Input = Input.RemoveIfFirst('[').RemoveIfLast(']');
            int counter = 0;
            bool insideB = false;
            int depth = 0;

            for (int x = 0; x < Input.Length; x++)
            {
                switch (Input[x])
                {
                    case '{':
                        if (depth > 0) { buffer.Append('{'); }
                        depth++;
                        break;

                    case '}':
                        depth--;
                        if (depth > 0) { buffer.Append('}'); }
                        break;

                    //case '[':
                    //case ']':
                    //    insideBr = !insideBr;
                    //    buffer.Append(Input[x]);
                    //    break;

                    case ',':
                        if (depth == 0)
                        {
                            JSONObjectOLD o = new JSONObjectOLD();
                            o.Name = counter.ToString();
                            counter++;
                            o.Raw = buffer.ToString();
                            buffer = new StringBuilder();
                            o.ParseRaw();
                            output.Add(o);
                        }
                        else
                        {
                            buffer.Append(',');
                        }
                        break;

                    default:
                        buffer.Append(Input[x]);
                        break;
                }

            }
            if (buffer.Length > 0)
            {
                JSONObjectOLD o = new JSONObjectOLD();
                o.Name = counter.ToString();
                o.Raw = buffer.ToString();
                o.ParseRaw();
                output.Add(o);
            }
            return output;
        }
Example #2
0
        public void ParseRaw()
        {
            int split = this.Raw.IndexOf(':');
            if (split == -1) { return; }
            string[] items = new string[2];
            items[0] = this.Raw.Substring(0, split);
            items[1] = this.Raw.Substring(split + 1);

            //if (items[1].Trim().EndsWith("}")) { items[1] = items[1].Remove(items[1].Length - 1); }

            this.Name = items[0].Replace("\"", "").Trim();

            if (items[1].Trim().StartsWith("\""))
            {
                this.Type = JSONType.String;
                string v = items[1].Replace("\\\"", "|||||");
                v = v.Replace("\"", "");
                v = v.Replace("|||||", "\\\"");
                this.Value = v.Trim();
            }
            else if (items[1].Trim().StartsWith("'"))
            {
                this.Type = JSONType.String;
                this.Value = items[1].Replace("'", "").Trim();
            }
            else if (items[1].Trim().CanConvert(typeof(System.Int32)))
            {
                this.Type = JSONType.Number;
                this.Value = Convert.ToInt32(items[1]);
            }
            else if (items[1].Trim().CanConvert(typeof(bool)))
            {
                this.Type = JSONType.Boolean;
                this.Value = Convert.ToBoolean(items[1].Trim());
            }
            else if (items[1].Trim().StartsWith("["))
            {
                char next = items[1].Trim().NextRealCharacter(1);
                if (next == '{') //We are dealing with Objects here.
                {
                    this.Type = JSONType.ObjectArray;
                    string arrayinput = items[1].Trim().Substring(1);
                    if (arrayinput.EndsWith("]")) { arrayinput = arrayinput.Remove(arrayinput.Length - 1); }
                    this.Value = JSONObjectOLD.GetObjects(arrayinput);
                }
                else  // Raw text
                {
                    this.Type = JSONType.Raw;
                    this.Value = items[1];
                }
            }
            else if (items[1].Trim().StartsWith("{"))
            {
                this.Type = JSONType.Object;
                JSONObjectOLD o = new JSONObjectOLD();
                o.Name = this.Name;
                o.Raw = items[1].Trim().Substring(1, items[1].Trim().Length - 2);
                this.Value = o;
                o.ParseRaw();
            }
            else
            {
                this.Type = JSONType.Raw;
                this.Value = items[1].Trim();
            }
        }