zoukankan      html  css  js  c++  java
  • P31RestKit.dll 2.0 Unity3d json

    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;
    }

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

  • 相关阅读:
    n的阶乘
    二叉树遍历
    二分查找练习
    字符串中最长回文序列求解
    复数集合
    AppCrawler自动化遍历使用详解(版本2.1.0 )(转)
    谷歌驱动下载链接
    谷歌浏览器插件
    Pycharm破解方法
    go学习链接
  • 原文地址:https://www.cnblogs.com/zfyouxi/p/4727448.html
Copyright © 2011-2022 走看看