hola estoy intentando aprender a serializar y en la página con json e encontrado esta libreria en la pagina de json pero no se muy bien como funciona aun si alguien me pudiera ayudar a explicarme linea por linea que hace lo agradecería mucho
using System;
using System.Collections.Generic;
using System.Text;
namespace Example
{
using System.Net.Json;
class Program
{
const string jsonText =
"{"+
" \"FirstValue\": 1.1,"+
" \"SecondValue\": \"some text\"," +
" \"TrueValue\": true" +
"}";
static void Main(string[] args)
{
Console.WriteLine();
Console.WriteLine("Source data:");
Console.WriteLine(jsonText);
Console.WriteLine();
JsonTextParser parser = new JsonTextParser();
JsonObject obj = parser.Parse(jsonText);
Console.WriteLine();
Console.WriteLine("Parsed data with indentation in JSON data format:");
Console.WriteLine(obj.ToString());
Console.WriteLine();
JsonUtility.GenerateIndentedJsonText = false;
Console.WriteLine();
Console.WriteLine("Parsed data without indentation in JSON data format:");
Console.WriteLine(obj.ToString());
Console.WriteLine();
Console.WriteLine();
Console.WriteLine("Parsed object contains these nested fields:");
foreach (JsonObject field in obj as JsonObjectCollection)
{
string name = field.Name;
string value = string.Empty;
string type = field.GetValue().GetType().Name;
switch(type)
{
case "String":
value = (string)field.GetValue();
break;
case "Double":
value = field.GetValue().ToString();
break;
case "Boolean":
value = field.GetValue().ToString();
break;
default:
throw new NotSupportedException();
}
Console.WriteLine("{0} {1} {2}",
name.PadLeft(15), type.PadLeft(10), value.PadLeft(15));
}
Console.WriteLine();
Console.WriteLine();
JsonObjectCollection collection = new JsonObjectCollection();
collection.Add(new JsonStringValue("FirstName", "Shadu"));
collection.Add(new JsonStringValue("LastName", "Romero"));
collection.Add(new JsonNumericValue("Age", 23));
collection.Add(new JsonStringValue("Email", "romero@outlook.com"));
collection.Add(new JsonBooleanValue("HideEmail", true));
Console.WriteLine("Generated object:");
JsonUtility.GenerateIndentedJsonText = true;
Console.WriteLine(collection);
Console.WriteLine();
Console.ReadLine();
}
}
}