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);
        }
    }
  • 相关阅读:
    Docker Registry 管理镜像
    Dockerfile 构建镜像
    制作docker镜像
    docker 使用及基本命令
    centos7 安装 docker
    spring-boot-devtools 热部署
    mysql库复制
    windows下安装和设置gradle
    springboot项目搭建
    下载和安装
  • 原文地址:https://www.cnblogs.com/lzy575566/p/7676544.html
Copyright © 2011-2022 走看看