Advertisement
OwlyOwl

json parse

Mar 23rd, 2021
686
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.52 KB | None | 0 0
  1. using Kuhpik;
  2. using System;
  3. using System.Collections;
  4. using System.Collections.Generic;
  5. using System.IO;
  6. using TMPro;
  7. using UnityEngine;
  8.  
  9. public class ShowResultSystem : GameSystem, IIniting
  10. {
  11.     [SerializeField] TextMeshProUGUI result;
  12.     [SerializeField] TextMeshProUGUI record;
  13.     [SerializeField] TextMeshProUGUI leaderboardPlayers;
  14.     [SerializeField] TextMeshProUGUI leaderboardScore;
  15.  
  16.     //private string jsonString;
  17.     private string path = "";
  18.     private string saveFileName = "leaderboard.json";
  19.  
  20.     void IIniting.OnInit()
  21.     {
  22.         result.text = "Result: " + game.latestResult;
  23.         record.text = "Record: " + player.record;
  24.  
  25. //#if UNITY_ANDROID && !UNITY_EDITOR
  26. //path = Path.Combine(Application.persistentDataPath, saveFileName);
  27. //#else
  28. //        path = Path.Combine(Application.dataPath, saveFileName);
  29. //#endif
  30.  
  31.  
  32.         var jsonTextFile = Resources.Load<TextAsset>("leaderboard");
  33.         string content = jsonTextFile.ToString();
  34.  
  35.  
  36.  
  37.  
  38.         //TextAsset file = Resources.Load(saveFileName) as TextAsset;
  39.         //string content = File.ReadAllText(path);
  40.         //jsonString = File.ReadAllText(path);
  41.        
  42.         ScoreList newList = JsonUtility.FromJson<ScoreList>("{\"players\":" + content + "}");
  43.  
  44.         foreach (var player in newList.players)
  45.         {
  46.             leaderboardPlayers.text += player.name + "\n";
  47.         }
  48.  
  49.         foreach (var score in newList.players)
  50.         {
  51.             leaderboardScore.text += score.score + "\n";
  52.         }
  53.     }
  54. }
  55.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement