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(); }
}
}