• 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);
        }
    }
  • 相关阅读:
    django 自定义用户身份验证
    登录验证算法
    Scrapy
    爬虫性能相关
    Beautifulsoup模块
    selenium模块
    Cookie&Session
    Django Admin 本质
    JavaScript自执行函数和jquery扩展方法
    JS作用域与词法分析
  • 原文地址:https://www.cnblogs.com/lzy575566/p/7676544.html
Copyright © 2020-2023  润新知