zoukankan      html  css  js  c++  java
  • Unity Json解析IPA

      今天看到一个unity 自带的解析json的IPA,感觉比litjson好用很多,废话不多,上代码

    using System.Collections;
    using System.Collections.Generic;
    using UnityEngine;
    using System;
    using System.IO;
    
    [Serializable]
    public class MyClass
    {
        public int level;
        public float timeElapsed;
        public string playerName;
    }
    public class Srealizable : MonoBehaviour {
        string json;
        string path;
        private void Awake()
        {
                path = Application.streamingAssetsPath + "/myclas.txt";
        }
        // Use this for initialization
        void Start () { Test1();}
        public void Test1()
        {
            MyClass myObject = new MyClass();
            myObject.level = 1;
            myObject.timeElapsed = 47.5f;
            myObject.playerName = "Dr Charles Francis";
            json = JsonUtility.ToJson(myObject);
            Debug.LogError(json);
            //  DesTets();
            WritOBJ();
        }
    
        public void DesTets()
        {
          MyClass  Obj = JsonUtility.FromJson<MyClass>(json);
            Debug.LogError(Obj.level);
        }
    
        void WritOBJ()
        {
            StreamWriter streamWriter = new StreamWriter(path,true);
          //  byte[] data = System.Text.Encoding.Unicode.GetBytes(json);
            streamWriter.Write(json);
            streamWriter.Close();
            ReadOBJ();
        }
        void ReadOBJ()
        {
            StreamReader streamReader = new StreamReader(path);
           string str=  streamReader.ReadToEnd();
            streamReader.Close();
            MyClass obj = JsonUtility.FromJson<MyClass>(str);
            Debug.LogError(obj.level + "  " + obj.playerName + "   " + obj.timeElapsed);
        }
    }
  • 相关阅读:
    结对作业评分
    Week6&7——第一次项目冲刺(Alpha版本)
    软工辅修团队项目选题参考
    Week5——团队选题&需求分析
    Week4——结对练习&团队作业1
    nginx与Apache的对比以及优缺点
    oracle数据库-错误编码大全
    spring MVC原理
    Java操作Memcached
    zookeeper应用场景-java
  • 原文地址:https://www.cnblogs.com/lzy575566/p/7676544.html
Copyright © 2011-2022 走看看