Example #1
0
    public void Stringify_OnlyTArrayTest_float(Result result)
    {
        var json = JsonStringify.Stringify(StArr.To(1, 2, 3.14f));

        if (json != "[1,2,3.14]")
        {
            result.Invoke(Fail("Parsed to " + json));
        }
        result.Invoke(Pass());
    }
Example #2
0
        public static string ToJson(this object obj, bool addFormating = false)
        {
            var serializer = new JsonStringify(obj);

            if (addFormating)
            {
                serializer.Formatting = Newtonsoft.Json.Formatting.Indented;
            }
            return(serializer.ToString());
        }
Example #3
0
    public void Stringify_OnlyTArrayTest_string(Result result)
    {
        var json = JsonStringify.Stringify(StArr.To(1, 2, "abs"));

        if (json != "[1,2,\"abs\"]")
        {
            result.Invoke(Fail("Parsed to " + json));
        }
        result.Invoke(Pass());
    }
Example #4
0
    public void Stringify_OnlyTArrayTest_int_1(Result result)
    {
        var json = JsonStringify.Stringify(StArr.To(1));

        if (json != "[1]")
        {
            result.Invoke(Fail("Parsed to " + json));
        }
        result.Invoke(Pass());
    }
Example #5
0
    public void Stringify_OnlyObjectTest(Result result)
    {
        // {}
        var json = JsonStringify.Stringify(null);

        if (json != "{}")
        {
            result.Invoke(Fail("Parsed to " + json));
        }
        result.Invoke(Pass());
    }
Example #6
0
    public void Stringify_SimpleObjectTest_2(Result result)
    {
        // { "a":"b" , "c":"d"}
        var json = JsonStringify.Stringify(new Dictionary <string, string> {
            { "a", "b" }, { "c", "d" }
        });

        if (json != "{\"a\":\"b\",\"c\":\"d\"}")
        {
            result.Invoke(Fail("Parsed to " + json));
        }
        result.Invoke(Pass());
    }
Example #7
0
    public void Stringify_ArrayIncludeObjectTest_1(Result result)
    {
        // {"a":[1,2,3]}
        var json = JsonStringify.Stringify(new ObjDict {
            { "a", StArr.To(1, 2, 3).ToObjArr() }
        });

        if (json != "{\"a\":[1,2,3]}")
        {
            result.Invoke(Fail("Parsed to " + json));
        }
        result.Invoke(Pass());
    }
Example #8
0
        public string ToJson()
        {
            // デフォルトでは付属オブジェクトを直列化するものとして
            // data2jsonにFalseを指定している場合だけ拒否する
            // 既存コードに変更を加えないで対応するため
            var data2json = Match("data2json", "False") == false;

            if (mObjectData != (object)NULL.Null && data2json)
            {
                Set("mObjectData", mObjectData.ToJson());
            }
            var str = JsonStringify.Stringify(this);

            return(str);
        }
Example #9
0
    public void Stringify_ObjectIncludeObjectTest(Result result)
    {
        // { a:{e:f, g:h}, c:d }
        var json = JsonStringify.Stringify(new ObjDict {
            { "a", new Dictionary <string, string> {
                  { "e", "f" }, { "g", "h" }
              } }, { "c", "d" }
        });

        if (json != "{\"a\":{\"e\":\"f\",\"g\":\"h\"},\"c\":\"d\"}")
        {
            result.Invoke(Fail("Parsed to " + json));
        }
        result.Invoke(Pass());
    }
Example #10
0
    public void Stringify_ArrayIncludeObjectTest_2(Result result)
    {
        // {"a":[1,2,3],"c":"d"}

        var json = JsonStringify.Stringify(new ObjDict {
            { "a", StArr.To(1, 2, 3) }, { "c", "d" }
        });

        if (json != "{\"a\":[1,2,3],\"c\":\"d\"}")
        {
            result.Invoke(Fail("Parsed to " + json));
        }

        result.Invoke(Pass());
    }
Example #11
0
    public static string ToJson(this object obj)
    {
        if (obj.IsNull())
        {
            return("''");
        }
        var type = obj.GetType();

        if (type.IsArray)
        {
            return(JsonStringify.Stringify(obj));
        }
        if (type.IsPrimitive)
        {
            return("'" + obj.ToString() + "'");
        }
        return(JsonStringify.Stringify(obj));
    }