36 lines
976 B
C#
36 lines
976 B
C#
using Newtonsoft.Json;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
|
|
public class JsonTest : MonoBehaviour
|
|
{
|
|
public class TestPerson
|
|
{
|
|
public string Name { get; set; }
|
|
public int Age { get; set; }
|
|
public string Email { get; set; }
|
|
}
|
|
void Start()
|
|
{
|
|
TestPerson person = new TestPerson
|
|
{
|
|
Name = "John Doe",
|
|
Age = 30,
|
|
Email = "john.doe@example.com"
|
|
};
|
|
|
|
string jsonString = JsonConvert.SerializeObject(person, Formatting.Indented);
|
|
Debug.Log("Serialized JSON string:");
|
|
Debug.Log(jsonString);
|
|
|
|
TestPerson deserializedPerson = JsonConvert.DeserializeObject<TestPerson>(jsonString);
|
|
Debug.Log("Deserialized Person object:");
|
|
Debug.Log($"Name: {deserializedPerson.Name}");
|
|
Debug.Log($"Age: {deserializedPerson.Age}");
|
|
Debug.Log($"Email: {deserializedPerson.Email}");
|
|
}
|
|
|
|
|
|
}
|