Esempio n. 1
0
    static JsonBase()
    {
        writesettings = new JsonWriterSettings();
        writesettings.AddTypeConverter(new Vector2Converter());
        writesettings.AddTypeConverter(new Vector3Converter());
        writesettings.AddTypeConverter(new ColorConverter());

        readersettings = new JsonReaderSettings();
        readersettings.AddTypeConverter(new Vector2Converter());
        readersettings.AddTypeConverter(new Vector3Converter());
        readersettings.AddTypeConverter(new ColorConverter());
    }
Esempio n. 2
0
        public Packet()
        {
            type      = 0;
            operation = 0;

            output = new StringBuilder();
            JsonWriterSettings settings = new JsonWriterSettings();

            settings.PrettyPrint = false;
            settings.AddTypeConverter(new VectorConverter());
            settings.AddTypeConverter(new QuaternionConverter());
            // TODO: Add any other TypeConverters here
            writer = new JsonWriter(output, settings);
        }
Esempio n. 3
0
    public static string Serialize(object obj)
    {
        System.Text.StringBuilder output = new System.Text.StringBuilder();

        JsonWriterSettings settings = new JsonWriterSettings();

        settings.PrettyPrint = true;
        settings.AddTypeConverter(new VectorConverter());
        settings.AddTypeConverter(new ColorConverter());
        settings.AddTypeConverter(new QuaternionConverter());

        JsonWriter writer = new JsonWriter(output, settings);

        writer.Write(obj);

        return(output.ToString());
    }
Esempio n. 4
0
    private static void init()
    {
        if (!init_)
        {
            rsettings_.AddTypeConverter(color);
            wsettings_.AddTypeConverter(color);
            init_ = true;

            settings.PrettyPrint = false;
            settings.AddTypeConverter(color);
        }
    }
Esempio n. 5
0
    public static T reader <T>(string json)
    {
        if (affixConverter_ == null)
        {
            affixConverter_ = new JsonData.AffixConverter();
            rsettings_.AddTypeConverter(affixConverter_);
            wsettings_.AddTypeConverter(affixConverter_);
        }
        JsonReader reader = new JsonReader(json, rsettings_);

        return((T)reader.Deserialize(typeof(T)));
    }
Esempio n. 6
0
        public void OpenSerialize()
        {
            Debug.LogError("OpenSerialize");
#if ASTAR_NO_JSON
            Debug.LogError("FuckNoJson");
#endif
            // Create a new zip file, here we will store all the data
            zip = new ZipFile();
            zip.AlternateEncoding      = System.Text.Encoding.UTF8;
            zip.AlternateEncodingUsage = ZipOption.Always;

#if !ASTAR_NO_JSON
            // Add some converters so that we can serialize some Unity types
            writerSettings = new JsonWriterSettings();
            writerSettings.AddTypeConverter(new VectorConverter());
            writerSettings.AddTypeConverter(new BoundsConverter());
            writerSettings.AddTypeConverter(new LayerMaskConverter());
            writerSettings.AddTypeConverter(new MatrixConverter());
            writerSettings.AddTypeConverter(new GuidConverter());
            writerSettings.AddTypeConverter(new UnityObjectConverter());

            writerSettings.PrettyPrint = settings.prettyPrint;
#endif
            meta = new GraphMeta();
        }
Esempio n. 7
0
    public static string write <T>(T obj)
    {
        JsonWriterSettings settings = new JsonWriterSettings();

        settings.PrettyPrint = false;
        settings.AddTypeConverter(new JsonData.AffixConverter());

        StringBuilder output = new StringBuilder();
        JsonWriter    writer = new JsonWriter(output, settings);

        writer.Write(obj);
        return(output.ToString());
    }
Esempio n. 8
0
    /// <summary>
    /// Initializes the Json Object Conversion
    /// </summary>
    public static void initJsonObjectConversion()
    {
        if (isInitialized)
        {
            return;
        }

        jsonReaderSettings             = new JsonReaderSettings();
        jsonWriterSettings             = new JsonWriterSettings();
        jsonWriterSettings.PrettyPrint = false;

        jsonConverters = createJsonConverters();

        foreach (JsonConverter jsonConverter in jsonConverters)
        {
            jsonReaderSettings.AddTypeConverter(jsonConverter);
            jsonWriterSettings.AddTypeConverter(jsonConverter);
        }

        isInitialized = true;
    }
Esempio n. 9
0
        public void OpenSerialize()
        {
            zip = new ZipFile();
            zip.AlternateEncoding      = System.Text.Encoding.UTF8;
            zip.AlternateEncodingUsage = ZipOption.Always;

            writerSettings = new JsonWriterSettings();
            writerSettings.AddTypeConverter(new VectorConverter());
            writerSettings.AddTypeConverter(new BoundsConverter());
            writerSettings.AddTypeConverter(new LayerMaskConverter());
            writerSettings.AddTypeConverter(new MatrixConverter());
            writerSettings.AddTypeConverter(new GuidConverter());
            writerSettings.AddTypeConverter(new UnityObjectConverter());

            //writerSettings.DebugMode = true;
            writerSettings.PrettyPrint = settings.prettyPrint;
            meta = new GraphMeta();
        }
Esempio n. 10
0
    void PrintResults(string rawJson)
    {
        // Raw output:

        /*DB.Log(DC.Log("******** raw string from Twitter ********"));
         * DB.Log(DC.Log(rawJson));
         *
         *
         * // Turn the JSON into C# objects
         * var search = JsonReader.Deserialize<TwitterSearchResults>(rawJson);
         *
         *
         * // iterate through the array of results;
         * DB.Log(DC.Log("******** search results ********"));
         *
         *
         * foreach (var tweet in search.results) {
         *      DB.Log(DC.Log(tweet.from_user_name + " : " + tweet.text));
         * }
         *
         * DB.Log(DC.Log("******** serialize an entity ********"));
         *
         * JsonWriterSettings settings = new JsonWriterSettings();
         * settings.PrettyPrint = true;
         *
         * System.Text.StringBuilder output = new System.Text.StringBuilder();
         *
         * JsonWriter writer = new JsonWriter (output,settings);
         * writer.Write (search.results[0]);
         *
         * // this turns a C# object into a JSON string.
         * string json = output.ToString();//JsonWriter.Serialize();
         *
         * DB.Log(DC.Log(json));*/

        for (int i = 0; i < 10; i++)
        {
            System.Diagnostics.Stopwatch watch = new System.Diagnostics.Stopwatch();
            watch.Start();
            System.Text.StringBuilder output = new System.Text.StringBuilder();

            Debug.Log("+++ Serializing +++");
            JsonWriterSettings settings = new JsonWriterSettings();
            settings.PrettyPrint = false;
            settings.AddTypeConverter(new VectorConverter());

            TestClass test = new TestClass();
            test.vec.y = 128.513589999F;
            JsonWriter writer = new JsonWriter(output, settings);

            Debug.Log("+++ Writing +++");
            writer.Write(test);

            if (i == 0)
            {
                Debug.Log(output.ToString());
            }

            Debug.Log("+++ Deserializing - Init +++");
            JsonReaderSettings settings2 = new JsonReaderSettings();
            settings2.AddTypeConverter(new VectorConverter());
            JsonReader reader = new JsonReader(output.ToString(), settings2);

            Debug.Log("+++ Deserializing +++");
            TestClass deserialized = reader.Deserialize <TestClass>();

            watch.Stop();
            Debug.Log((watch.ElapsedTicks * 0.0001).ToString("0.00"));
            Debug.Log(deserialized.vec.y.ToString("r"));
        }
    }