/// <summary>
		/// Ctor
		/// </summary>
		/// <param name="settings">JsonWriterSettings</param>
		public JsonDataReader(JsonReaderSettings settings)
		{
			if (settings == null)
			{
				throw new ArgumentNullException("settings");
			}
			this.Settings = settings;
		}
Example #2
0
    void OnGUI()
    {
        content = GUI.TextArea(new Rect(100, 100, 400, 100), content);

           /* if (GUI.Button(new Rect(330, 60, 60, 30), "Little jasson"))
        {
            Debug.Log("write jsson");

            TextWriter wr = new StreamWriter("students.txt");
            JsonWriter jsonwr = new JsonWriter(wr);
            jsonwr.IndentValue = 0;
            JsonMapper.ToJson(st1, jsonwr);
            jsonwr.WriteObjectStart();

            JsonMapper.ToJson(st2, jsonwr);
            wr.Close();

        }*/

        if (GUI.Button(new Rect(380, 60, 60, 30), "FX jasson"))
        {
            /*Классы короткая запись*/
            string json = JsonFx.Json.JsonWriter.Serialize(st1);
           // Debug.Log(json);
            Student st3 = JsonFx.Json.JsonReader.Deserialize<Student>(json);
            //Debug.Log("age " + st3.age + " count " + st3.count[5] + " name " + st3.name);

            /*массив*/

            JsonWriterSettings settw = new JsonWriterSettings();
            settw.TypeHintName = "__type";
            JsonReaderSettings settr = new JsonReaderSettings();
            settr.TypeHintName = "__type";

            /*пример чтоб разобраться, но либа работает только с классами нормально. */
            System.Text.StringBuilder builder=new System.Text.StringBuilder();
            JsonWriter wr = new JsonWriter(builder,settw);
                Student[] arr = new Student[3];
                arr[0] = st1;
                arr[1] = st2;
                arr[2] = st3;
                wr.Write(arr);
                System.IO.File.WriteAllText("testJSON.txt", builder.ToString());

            string jsonText = System.IO.File.ReadAllText("testJSON.txt");
            //Debug.Log(""+jsonText);
            Student[] tempSt = JsonReader.Deserialize<Student[]>(jsonText);
            content = "";
                foreach( var s in tempSt)
                    content +="" + s.name+System.Environment.NewLine;

        }
    }
	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 #4
0
        public static void RunTest(TextWriter writer, string unitTestsFolder, string outputFolder)
        {
            string[] unitTests = Directory.GetFiles(unitTestsFolder, UnitTestsFiles, SearchOption.AllDirectories);
            if (unitTests.Length > 0)
            {
                JsonReaderSettings readerSettings = new JsonReaderSettings();
                readerSettings.TypeHintName = StronglyTyped.MyTypeHintName;
                readerSettings.AllowNullValueTypes = true;
                readerSettings.AllowUnquotedObjectKeys = true;

                JsonWriterSettings writerSettings = new JsonWriterSettings();
                writerSettings.TypeHintName = StronglyTyped.MyTypeHintName;
                writerSettings.PrettyPrint = false;
                writerSettings.MaxDepth = 100;

                writer.WriteLine(JsonText.Seperator);
                writer.WriteLine("JsonReaderSettings:");
                new JsonWriter(writer).Write(readerSettings);

                writer.WriteLine(JsonText.Seperator);
                writer.WriteLine("JsonWriterSettings:");
                new JsonWriter(writer).Write(writerSettings);

                foreach (string unitTest in unitTests)
                {
                    string source = String.Empty;

                    try
                    {
                        writer.WriteLine(JsonText.Seperator);

                        source = File.ReadAllText(unitTest);
                        JsonReader jsonReader = new JsonReader(source, readerSettings);

                        object obj, obj2;
                        obj2 = obj = jsonReader.Deserialize();

                        do
                        {
                            writer.WriteLine("READ: {0}", unitTest.Replace(unitTestsFolder, ""));
                            writer.WriteLine("Result: {0}", (obj == null) ? "null" : obj.GetType().FullName);

                            obj = jsonReader.Deserialize();
                        } while (obj != null);

                        string outputFile = unitTest.Replace(unitTestsFolder, outputFolder);
                        string outputDir = Path.GetDirectoryName(outputFile);
                        if (!Directory.Exists(outputDir))
                        {
                            Directory.CreateDirectory(outputDir);
                        }
                        using (JsonWriter jsonWriter = new JsonWriter(outputFile, writerSettings))
                        {
                            jsonWriter.Write(obj2);
                        }
                    }
                    catch (JsonDeserializationException ex)
                    {
                        int col, line;
                        ex.GetLineAndColumn(source, out line, out col);

                        writer.WriteLine("ERROR: {0}", unitTest.Replace(unitTestsFolder, ""));
                        writer.WriteLine("-- \"{0}\" ({1}, {2})", ex.Message, line, col);
                        continue;
                    }
                    catch (Exception ex)
                    {
                        writer.WriteLine("ERROR: {0}", unitTest.Replace(unitTestsFolder, ""));
                        writer.WriteLine("-- \"{0}\"", ex.Message);
                        continue;
                    }
                }
            }
            else
            {
                writer.WriteLine(ErrorMessage);
            }
        }
		/// <summary>
		/// Builds a common settings objects
		/// </summary>
		/// <param name="allowNullValueTypes"></param>
		/// <returns></returns>
		public static JsonReaderSettings CreateSettings(bool allowNullValueTypes)
		{
			JsonReaderSettings settings = new JsonReaderSettings();

			settings.AllowNullValueTypes = allowNullValueTypes;

			return settings;
		}
Example #6
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;
    }
Example #7
0
 /// <summary>
 /// Ctor
 /// </summary>
 /// <param name="input">StringBuilder containing source</param>
 /// <param name="settings">JsonReaderSettings</param>
 public JsonReader(StringBuilder input, JsonReaderSettings settings)
 {
     this.Settings     = settings;
     this.Source       = input.ToString();
     this.SourceLength = this.Source.Length;
 }
Example #8
0
 /// <summary>
 /// Ctor
 /// </summary>
 /// <param name="input">string containing source</param>
 /// <param name="settings">JsonReaderSettings</param>
 public JsonReader(string input, JsonReaderSettings settings)
 {
     this.Settings     = settings;
     this.Source       = input;
     this.SourceLength = this.Source.Length;
 }
Example #9
0
 /// <summary>
 /// Ctor
 /// </summary>
 /// <param name="input">TextReader containing source</param>
 /// <param name="settings">JsonReaderSettings</param>
 public JsonReader(TextReader input, JsonReaderSettings settings)
 {
     this.Settings     = settings;
     this.Source       = input.ReadToEnd();
     this.SourceLength = this.Source.Length;
 }
Example #10
0
		private void loadcb (string datatxt)
		{
				JsonReaderSettings setting = new JsonReaderSettings ();
				setting.AddTypeConverter (new ColorConv ());
				JsonReader reader = new JsonReader (datatxt, setting);
				Debug.Log ("+++ Deserializing +++");
				listD = reader.Deserialize<gameLevelD> ();
				Debug.Log (datatxt);
		}