Advertisement
Guest User

Untitled

a guest
Oct 21st, 2019
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.10 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using SimpleJSON;
  4. using UnityEngine;
  5.  
  6. public class SimpleJSONExample : MonoBehaviour
  7. {
  8. string json = "{ \"highscores\" : " +
  9. " [" +
  10. " {" +
  11. " \"name\": \"jandu\"," +
  12. " \"score\": 1000" +
  13. " }," +
  14. " {" +
  15. " \"name\": \"bernat\"," +
  16. " \"score\": -2000" +
  17. " }" +
  18. " ]" +
  19. "}";
  20.  
  21. void Start(){
  22. JSONNode N = JSON.Parse(json);
  23.  
  24. JSONArray highscores = N["highscores"].AsArray;
  25.  
  26.  
  27. JSONObject tmpuser = new JSONObject();
  28. tmpuser.Add("name",new JSONString("pepito"));
  29. tmpuser.Add("score",new JSONNumber(2000));
  30.  
  31. highscores.Add(tmpuser);
  32.  
  33. for(int i=0; i<highscores.Count;i++){
  34. Debug.Log("Nombre: "+highscores[i]["name"]);
  35. Debug.Log("Score: "+highscores[i]["score"]);
  36. }
  37.  
  38. /*
  39. foreach(JSONNode v in highscores){
  40. Debug.Log("Nombre: "+v["name"]);
  41. Debug.Log("Score: "+v["score"]);
  42. }
  43. */
  44.  
  45.  
  46.  
  47. }
  48.  
  49. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement