Example #1
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);
        }
	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"));
		}
	}
Example #3
0
    void Awake()
    {
        jsonOutput = new System.Text.StringBuilder();

        JsonReaderSettings readSettings = new JsonReaderSettings();
        readSettings.AddTypeConverter(new RecordConverter());
        jsonReader = new JsonReader(jsonOutput, readSettings);

        JsonWriterSettings writeSettings = new JsonWriterSettings();
        writeSettings.PrettyPrint = true;
        writeSettings.AddTypeConverter(new RecordConverter());
        jsonWriter = new JsonWriter(jsonOutput, writeSettings);

        m_filePath = Application.dataPath;
        if (Application.platform == RuntimePlatform.OSXDashboardPlayer || Application.platform == RuntimePlatform.OSXEditor || Application.platform == RuntimePlatform.OSXPlayer || Application.platform == RuntimePlatform.OSXWebPlayer)
        {
            m_filePath += "/Score/";
        }
        else
        {
            m_filePath += "\\Score\\";
        }

        m_levelScore = 0f;
    }