JSONTools.JSONObjectOLD.ParseRaw C# (CSharp) Method

ParseRaw() public method

public ParseRaw ( ) : void
return void
        public void ParseRaw()
        {
            // split each section into an attribute
            bool insideD = false;
            bool insideS = false;
            int bDepth = 0;
            int brDepth = 0;
            JSONAttribute a = new JSONAttribute();

            for (int x = 0; x < this.Raw.Length; x++)
            {
                switch (this.Raw[x])
                {
                    case '"':
                        if (!insideS)
                        {
                            insideD = !insideD;
                        }
                        a.Raw += '"';
                        break;
                    case '\'':
                        if (!insideD)
                        {
                            insideS = !insideS;
                        }
                        a.Raw += '\'';
                        break;
                    case '[':
                        brDepth++;
                        a.Raw += '[';
                        break;
                    case ']':
                        brDepth--;
                        a.Raw += ']';
                        break;
                    case '{':
                        bDepth++;
                        a.Raw += '{';
                        break;
                    case '}':
                        bDepth--;
                        a.Raw += '}';
                        break;
                    case ',':
                        if (!insideD && !insideS && bDepth == 0 && brDepth == 0)
                        {
                            this.Values.Add(a);
                            a.Parent = this;
                            a = new JSONAttribute();
                        }
                        else
                        {
                            a.Raw += ',';
                        }
                        break;
                    case '\r':
                    case '\n':
                    case '\t':
                        if (insideD || insideS)
                        {
                            a.Raw += this.Raw[x];
                        }
                        break;
                    default:
                        a.Raw += this.Raw[x];
                        break;
                }
            }

            if (!string.IsNullOrEmpty(a.Raw) && a.Parent == null)
            {
                this.Values.Add(a);
                a.Parent = this;
            }

            foreach (JSONAttribute value in this.Values)
            {
                value.ParseRaw();
                if (value.Name == "id" && value.Type == JSONType.String) { this.Name = value.Value.ToString(); }
            }
        }

Usage Example

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;
        }
All Usage Examples Of JSONTools.JSONObjectOLD::ParseRaw