Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections;
- using System.Collections.Generic;
- using SimpleJSON;
- using UnityEngine;
- public class SimpleJSONExample : MonoBehaviour
- {
- string json = "{ \"highscores\" : " +
- " [" +
- " {" +
- " \"name\": \"jandu\"," +
- " \"score\": 1000" +
- " }," +
- " {" +
- " \"name\": \"bernat\"," +
- " \"score\": -2000" +
- " }" +
- " ]" +
- "}";
- void Start(){
- JSONNode N = JSON.Parse(json);
- JSONArray highscores = N["highscores"].AsArray;
- JSONObject tmpuser = new JSONObject();
- tmpuser.Add("name",new JSONString("pepito"));
- tmpuser.Add("score",new JSONNumber(2000));
- highscores.Add(tmpuser);
- for(int i=0; i<highscores.Count;i++){
- Debug.Log("Nombre: "+highscores[i]["name"]);
- Debug.Log("Score: "+highscores[i]["score"]);
- }
- /*
- foreach(JSONNode v in highscores){
- Debug.Log("Nombre: "+v["name"]);
- Debug.Log("Score: "+v["score"]);
- }
- */
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement