P31RestKit.dll 2.0 Unity3d json

时间:2023-12-30 11:30:50
using System.Collections.Generic;
using UnityEngine;
using System.Collections;
using Prime31; public class JsonTest : MonoBehaviour
{
// Use this for initialization
void Start () {
Player player = new Player()
{
Name = "Lee",
Age = 19
}; string jsonString = Json.encode(player); Debug.Log(jsonString); player = Json.decode<Player>(jsonString); Debug.Log(player.Name);
Debug.Log(player.Age); List<Player> playerList = new List<Player>()
{
new Player() {Name = "wang", Age = 12},
new Player() {Name = "wang2", Age = 13},
new Player() {Name = "wang3", Age = 14},
new Player() {Name = "wang4", Age = 15},
new Player() {Name = "wang5", Age = 16},
}; string playerListString = Json.encode(playerList); Debug.Log(playerListString); List<Player> playerList2;
playerList2 = Json.decode<List<Player>>(playerListString); foreach (var p in playerList2)
{
Debug.Log(p.Name);
Debug.Log(p.Age);
}
} } public class Player
{
public string Name;
public int Age;
}

版权声明:本文博客原创文章。博客,未经同意,不得转载。