예제 #1
0
    public string ToString(string curIndent, string indent)
    {
        bool flag = curIndent != null;

        if (this.IsString())
        {
            return(string.Concat("\"", JSONValue.EncodeString(this.AsString(false)), "\""));
        }

        if (this.IsFloat())
        {
            return(this.AsFloat(false).ToString());
        }

        if (this.IsList())
        {
            string str   = "[";
            string empty = string.Empty;
            foreach (JSONValue jSONValue in this.AsList(false))
            {
                str   = string.Concat(str, empty, jSONValue.ToString());
                empty = ", ";
            }

            return(string.Concat(str, "]"));
        }

        if (!this.IsDict())
        {
            if (this.IsBool())
            {
                return(!this.AsBool(false) ? "false" : "true");
            }

            if (!this.IsNull())
            {
                throw new JSONTypeException("Cannot serialize json value of unknown type");
            }

            return("null");
        }

        string str1   = string.Concat("{", (!flag ? string.Empty : "\n"));
        string empty1 = string.Empty;

        foreach (KeyValuePair <string, JSONValue> keyValuePair in this.AsDict(false))
        {
            string    str2     = str1;
            object[]  objArray = new object[] { str2, empty1, curIndent, indent, '\"', JSONValue.EncodeString(keyValuePair.Key), "\" : ", null };
            JSONValue value    = keyValuePair.Value;
            objArray[7] = value.ToString(string.Concat(curIndent, indent), indent);
            str1        = string.Concat(objArray);
            empty1      = string.Concat(", ", (!flag ? string.Empty : "\n"));
        }

        return(string.Concat(str1, (!flag ? string.Empty : string.Concat("\n", curIndent)), "}"));
    }
예제 #2
0
    public string ToString(string curIndent, string indent)
    {
        bool flag = curIndent != null;

        if (this.IsString())
        {
            return("\"" + JSONValue.EncodeString(this.AsString(false)) + "\"");
        }
        if (this.IsFloat())
        {
            return(this.AsFloat(false).ToString());
        }
        if (this.IsList())
        {
            string str  = "[";
            string str2 = string.Empty;
            foreach (JSONValue current in this.AsList(false))
            {
                str  = str + str2 + current.ToString();
                str2 = ", ";
            }
            return(str + "]");
        }
        if (this.IsDict())
        {
            string text  = "{" + ((!flag) ? string.Empty : "\n");
            string text2 = string.Empty;
            foreach (KeyValuePair <string, JSONValue> current2 in this.AsDict(false))
            {
                string text3 = text;
                text = string.Concat(new object[]
                {
                    text3,
                    text2,
                    curIndent,
                    indent,
                    '"',
                    JSONValue.EncodeString(current2.Key),
                    "\" : ",
                    current2.Value.ToString(curIndent + indent, indent)
                });
                text2 = ", " + ((!flag) ? string.Empty : "\n");
            }
            return(text + ((!flag) ? string.Empty : ("\n" + curIndent)) + "}");
        }
        if (this.IsBool())
        {
            return((!this.AsBool(false)) ? "false" : "true");
        }
        if (this.IsNull())
        {
            return("null");
        }
        throw new JSONTypeException("Cannot serialize json value of unknown type");
    }