Add() public method

public Add ( string aKey, JSONNode aItem ) : void
aKey string
aItem JSONNode
return void
示例#1
0
        public void readHosts()
        {
            string path = Application.persistentDataPath;

            if (!path.EndsWith("/"))
            {
                path += "/";
            }

            PlayerPrefs.Save();
            //PlayerPrefs.DeleteAll();

            SimpleJSON.JSONNode hostfile = new SimpleJSON.JSONClass();

#if !(UNITY_WEBPLAYER || UNITY_WEBGL)
            if (!System.IO.File.Exists("host.cfg"))
            {
                hostfile.Add("host", new SimpleJSON.JSONData("http://localhost:3000/api/proxy/gleaner/collector/"));
                hostfile.Add("trackingCode", new SimpleJSON.JSONData("asdasdasdasda"));
                System.IO.File.WriteAllText("host.cfg", hostfile.ToString());
            }
            else
            {
                hostfile = SimpleJSON.JSON.Parse(System.IO.File.ReadAllText("host.cfg"));
            }
#endif

            PlayerPrefs.SetString("host", hostfile["host"]);
            PlayerPrefs.SetString("trackingCode", hostfile["trackingCode"]);
            PlayerPrefs.Save();


            //End tracker data loading
        }
示例#2
0
    static void ExportResource()
    {
        int StageNum = 1;
        string fileName = "Stage" + StageNum + ".json";

        Transform tf = GameObject.Find("BlockRoot").transform;

        string seedString = "{\"blocks\":[]}";

        JSONNode node = JSON.Parse(seedString);

        Transform[] arTF = tf.GetComponentsInChildren<Transform>();
        for (int i = 1; i < arTF.Length; i++)
        {
            Transform subtf = arTF[i];

            JSONClass subNode = new JSONClass();

            subNode.Add("type", "Normal");
            subNode.Add("posX", subtf.position.x + "");
            subNode.Add("posY", subtf.position.y + "");

            node["blocks"][-1] = subNode;
        }

        Debug.Log(node.ToString());
        writeStringToFile(node.ToString(), fileName);
    }
	//JSON Format:

	/*
	{
		"session": {
			"id": "session1234",
			"player": "user123",
			"game": "game1",
			"version": "version 1.0"
		},
		
		"play_events" :
		[ 
		{  "time": "2015-02-17T22:43:45-5:00", "event": "PowerUp.FireBall", "value": "1.0", "level": "1-1"},
		{  "time": "2015-02-17T22:45:45-5:00", "event": "PowerUp.Mushroom", "value": "2.0", "level": "1-1"}
		 ]
	}
	*/

	public static string ToJSON(Gloggr_Report r)
	{
	
		JSONNode n = new JSONClass();
		
		
		
		n.Add ("session",  Gloggr_SessionHeader.ToJSONObject(r.session)  );
		
		JSONArray a = new JSONArray();
		
		foreach(Gloggr_PlayEvent e in r.play_events)
		{
			a.Add(Gloggr_PlayEvent.ToJSONObject(e));
		}
		
		n.Add ("play_events", a);
		
		return n.ToString();	
	
//		string json = JsonConvert.SerializeObject(e, Formatting.Indented);
//		//from Gloggr_SessionHeader.ToJSON
//		//json = Gloggr_SessionHeader.FormatJSONKeys(json);
//		//from Gloggr_PlayEvent.ToJSON
//		//json = Gloggr_PlayEvent.FormatJSONKeys(json);
//		return json;
	}
    public void addGame(string title, bool ispublic)
    {
        JSONClass json = new JSONClass ();
        json.Add ("title", new JSONData (title));
        json.Add ("public", new JSONData (ispublic));

        net.POST (url, System.Text.Encoding.UTF8.GetBytes (json.ToString ()), trackHeaders, new GameCreatorListener ());
    }
示例#5
0
    public void login(string user, string pass)
    {
        JSONClass json = new JSONClass ();
        json.Add ("username", new JSONData (this.user));
        json.Add ("password", new JSONData (this.pass));

        www = net.POST (baseurl + loginurl, System.Text.Encoding.UTF8.GetBytes (json.ToString ()), trackHeaders, new LoginListener ());
    }
 public void OnException(Exception e)
 {
     ServiceAPI sp = AppConstant.GetServce();
     JSONClass json = new JSONClass();
     json.Add("userId",FB.UserId);
     json.Add("userName",AppConstant.GetUserName());
     AppConstant.GetStorageService(sp).InsertJSONDocument(AppConstant.DBName, AppConstant.CollectionName,json,this);
 }
示例#7
0
    public static byte[] BuildBytes_NewMatch()
    {
        SimpleJSON.JSONClass obj = new SimpleJSON.JSONClass();
        obj.Add("sender", AppWarp.localusername);
        obj.Add("type", "new_match");

        byte[] retVal = System.Text.Encoding.UTF8.GetBytes(obj.ToString());
        return retVal;
    }
示例#8
0
    public static byte[] BuildMessageBytes_OppName()
    {
        SimpleJSON.JSONClass obj = new SimpleJSON.JSONClass();
        obj.Add("sender", AppWarp.localusername);
        obj.Add("type", "oppName");

        byte[] retVal = System.Text.Encoding.UTF8.GetBytes(obj.ToString());
        return retVal;
    }
示例#9
0
 public static byte[] BuildMessageBytes_Move( string piece, int gbi )
 {
     SimpleJSON.JSONClass moveObj = new SimpleJSON.JSONClass();
     moveObj.Add("gridBoxIndex", gbi);
     moveObj.Add("sender", AppWarp.localusername);
     moveObj.Add("piece", piece);
     moveObj.Add("type", "move");
     return System.Text.Encoding.UTF8.GetBytes(moveObj.ToString());
 }
示例#10
0
    // 保存当前平台类型
    static void SavePlatform()
    {
        BuildTarget target = EditorUserBuildSettings.activeBuildTarget;

        BuildSetting(target);

        SimpleJSON.JSONClass json = new SimpleJSON.JSONClass();
        json.Add("platform", new SimpleJSON.JSONData((int)target));
        json.Add("version", new SimpleJSON.JSONData(ConstantData.mainVersion));

        IGG.FileUtil.SaveTextToFile(json.ToString(""), CommandHelper.OutputPath);
    }
	public static JSONNode ToJSONObject(Gloggr_SessionHeader e)
	{
		
		JSONNode n = new JSONClass();
		
		n.Add ("id", new JSONData( e.gSessionID));
		n.Add ("player", new JSONData(e.gPlayer));
		n.Add ("game", new JSONData(e.gGameName));
		n.Add ("version", new JSONData(e.gVersion));
		
		return n;
	}
	public static JSONNode ToJSONObject(Gloggr_PlayEvent e)
	{
		JSONNode n = new JSONClass();
		
		n.Add ("time", new JSONData( e.gTime));
		n.Add("event", new JSONData(e.gEvent));
		n.Add("value", new JSONData(e.gValue));
		n.Add("position", new JSONData(e.gPosition));
		n.Add("level", new JSONData(e.gLevel));
		
		return n;
	}
示例#13
0
    public void SaveName()
    {
        string path = Application.persistentDataPath;

        PlayerPrefs.SetInt("PreTestEnd", 0);
        PlayerPrefs.SetInt("PostTestEnd", 0);
        PlayerPrefs.SetInt("TeaTestEnd", 0);

        if (!path.EndsWith("/"))
        {
            path += "/";
        }

        if (PlayerPrefs.HasKey("username") && PlayerPrefs.GetString("username") != t.text)
        {
            if (System.IO.File.Exists(path + "tracesRaw.csv"))
            {
                System.IO.File.AppendAllText(path + PlayerPrefs.GetString("username") + ".csv.backup", System.IO.File.ReadAllText(path + "tracesRaw.csv"));
                System.IO.File.Delete(path + "tracesRaw.csv");
            }
        }
        PlayerPrefs.SetString("username", t.text);
        PlayerPrefs.SetString("password", t.text);
        PlayerPrefs.Save();
        //PlayerPrefs.DeleteAll();

        SimpleJSON.JSONNode hostfile = new SimpleJSON.JSONClass();

#if !(UNITY_WEBPLAYER || UNITY_WEBGL)
        if (!System.IO.File.Exists("host.cfg"))
        {
            hostfile.Add("host", new SimpleJSON.JSONData("http://192.168.175.117:3000/api/proxy/gleaner/collector/"));
            hostfile.Add("trackingCode", new SimpleJSON.JSONData("57d81d5585b094006eab04d6ndecvjlvjss8aor"));
            System.IO.File.WriteAllText("host.cfg", hostfile.ToString());
        }
        else
        {
            hostfile = SimpleJSON.JSON.Parse(System.IO.File.ReadAllText("host.cfg"));
        }
#endif

        PlayerPrefs.SetString("host", hostfile["host"]);
        if (PlayerPrefs.GetString("ActivitiesTracking") == null)
        {
            PlayerPrefs.SetString("trackingCode", hostfile["trackingCode"]);
        }
        PlayerPrefs.Save();

        TrackerObject.SetActive(true);
        //End tracker data loading
    }
示例#14
0
        public JSONClass GetJsonStatus()
        {
            var sj = new SimpleJSON.JSONClass();

            var jsonObj = new JSONClass();

            jsonObj.Add("id", new JSONData(id));
            if (mSocket != null)
            {
                var ip = mSocket.RemoteEndPoint as IPEndPoint;
                jsonObj.Add("ip", new JSONData(ip.ToString()));
                jsonObj.Add("Active", new JSONData("true"));
                jsonObj.Add("ReceivePackets", new JSONData(mReceivePacketCount));
                jsonObj.Add("ReceivePacketsSize", new JSONData(mReceivePacketSizeCount));
                jsonObj.Add("SendPackets", new JSONData(mSendPacketCount));
                jsonObj.Add("SendPacketsSize", new JSONData(mSendPacketSizeCount));
                jsonObj.Add("MsgQueueLength", new JSONData(msgBuffer.Count));
            }
            else
            {
                jsonObj.Add("Active", new JSONData("false"));
            }

            sj.Add("Agent", jsonObj);
            return(sj);
        }
示例#15
0
    public void addGameVersion(string id)
    {
        JSONClass json = new JSONClass ();
        json.Add ("gameId", id);

        net.POST (url + "/" + id + "/versions" , System.Text.Encoding.UTF8.GetBytes (json.ToString ()), trackHeaders, new GameVersionCreatorListener ());
    }
示例#16
0
    public void WriteMd5(SimpleJSON.JSONClass jobj)
    {
        var abPath = path.Replace("/", "_");
        var oj     = new SimpleJSON.JSONClass();

        oj.Add("md5", md5);
        jobj.Add(abPath, oj);
    }
示例#17
0
    public void WriteJson(SimpleJSON.JSONClass cl)
    {
        //var jd = new SimpleJSON.JSONData();
        //jd.Value =
        var fn     = Path.GetFileName(path);
        var abName = assetBundleFile.Replace("/", "_");

        cl.Add(fn, abName);
    }
示例#18
0
    void OnGUI()
    {
        if (Time.time % 2 < 1) {
            success = callBack.getResult();
        }
          	// For Setting Up ResponseBox.
        GUI.TextArea(new Rect(10,5,1300,175), success);

        //=========================================================================
        if (GUI.Button(new Rect(50, 200, 200, 30), "Run Java Code"))
        {
            App42Log.SetDebug(true);
            customCodeService = sp.BuildCustomCodeService(); // Initializing CustomCodeService.
            JSONClass jsonBody = new JSONClass();
            jsonBody.Add("name" ,"John");
            jsonBody.Add("age",30);
            customCodeService.RunJavaCode(cons.customServiceName,jsonBody,new CustomCodeResponse());
        }
    }
示例#19
0
    public void WriteJson(SimpleJSON.JSONClass jobj)
    {
        var abPath = path.Replace("/", "_");
        var ls     = new SimpleJSON.JSONArray();

        foreach (var dep in dependency)
        {
            ls.Add(dep.Replace("/", "_"));
        }
        jobj.Add(abPath, ls);
    }
示例#20
0
    void DoSync()
    {
		
		JSONClass cl = new JSONClass();
		
		JSONData dt_p1_mana = new JSONData(p1_mana);
		JSONData dt_p2_mana = new JSONData(p2_mana);
		JSONData dt_pop_all = new JSONData(pop_all);
		JSONData dt_pop_p1 = new JSONData(pop_p1);
		JSONData dt_pop_p2 = new JSONData(pop_p2);
		cl.Add("p1_mana",dt_p1_mana);
		cl.Add("p2_mana",dt_p2_mana);
		cl.Add("pop_all",dt_pop_all);
		cl.Add("pop_p1",dt_pop_p1);
		cl.Add("pop_p2",dt_pop_p2);
		
		string data = cl.SaveToBase64();
		
		pview.RPC("GameResources_DoSyncGet",PhotonTargets.Others,data);
        //nview.RPC("GameResources_DoSyncGet", RPCMode.Others, data);
		//Debug.Log ("sending data to client");
    }
示例#21
0
    public static byte[] BuildBytes_OnlineEvent( OnlineGameEvent _ge )
    {
        SimpleJSON.JSONClass obj = new SimpleJSON.JSONClass();
        obj.Add("sender", AppWarp.localusername);
        obj.Add("type", "online_event");
        obj.Add("gE", (int)_ge.gameEvent);
        if( _ge.gameEventProperty != null ) {
            obj.Add("hasEP", true);
            obj.Add("gEP", _ge.gameEventProperty);
        }
        else {
            obj.Add("hasEP", false);
            obj.Add("gEP", "");
        }

        byte[] retVal = System.Text.Encoding.UTF8.GetBytes(obj.ToString());
        return retVal;
    }
示例#22
0
    public IEnumerator writePlayerPrefs()
    {
        JSONClass root = new JSONClass();
        JSONClass users = new JSONClass();
        JSONClass wep = new JSONClass();
        JSONClass wep2 = new JSONClass();
        JSONArray weapons = new JSONArray();
        users.Add("user_id", ""+ PlayerPrefs.GetInt("user_id"));
        users.Add("total_kills", ""+ PlayerPrefs.GetInt("total_kills"));
        users.Add("total_points", ""+ PlayerPrefs.GetInt("total_points"));
        users.Add("red", "" + PlayerPrefs.GetFloat("BaseRed"));
        users.Add("green", "" + PlayerPrefs.GetFloat("BaseGreen"));
        users.Add("blue", "" + PlayerPrefs.GetFloat("BaseBlue"));
        users.Add("highest_round_reached", "" + PlayerPrefs.GetInt("highestRound"));
        users.Add("points_available", "" + PlayerPrefs.GetInt("points_available"));
        root.Add("user_params", users);

        Debug.Log(root.ToString());
        byte[] data = Encoding.UTF8.GetBytes(root.ToString());
        WWW www = new WWW(ROOT_URL + POST_USER_URL, data);
           yield return WaitForRequest(www);
    }
示例#23
0
        public override string ToString()
        {
            var sj = new SimpleJSON.JSONClass();

            var jsonObj = new JSONClass();

            jsonObj.Add("AgentCount", new JSONData(AgentCount));

            var jsonArray = new JSONArray();

            lock (agents)
            {
                foreach (var agent in agents)
                {
                    jsonArray.Add("Agent", agent.Value.GetJsonStatus());
                }
            }
            jsonObj.Add("Agents", jsonArray);
            sj.Add("AgentStatus", jsonObj);
            return(sj.ToString());
        }
示例#24
0
        public override string ToString()
        {
            var sj = new SimpleJSON.JSONClass();

            var jsonObj = new JSONClass();

            KeyValuePair <int, Actor>[] ad;
            lock (actorDict)
            {
                ad = actorDict.ToArray();
            }

            jsonObj.Add("ActorCount", new JSONData(ad.Length));
            var jsonArray = new JSONArray();

            foreach (var actor in ad)
            {
                var actorJson = new JSONClass();
                actorJson.Add("type", new JSONData(actor.Value.GetType().ToString()));
                var actorComponents = new JSONClass();

                /*
                 *  foreach (var compoent in actor.Value.GetComponents().Result)
                 *  {
                 *      actorComponents.Add("Component", new JSONData(compoent.GetType().ToString()));
                 *  }
                 */
                actorJson.Add("Components", actorComponents);
                actorJson.Add("Attribute", actor.Value.GetAttr());
                jsonArray.Add("Actor", actorJson);
            }
            jsonObj.Add("Actors", jsonArray);

            sj.Add("AtorStatus", jsonObj);
            return(sj.ToString());
        }
    void Test()
    {
        var N = JSONNode.Parse("{\"name\":\"test\", \"array\":[1,{\"data\":\"value\"}]}");
        N["array"][1]["Foo"] = "Bar";
        P("'nice formatted' string representation of the JSON tree:");
        P(N.ToString(""));
        P("");

        P("'normal' string representation of the JSON tree:");
        P(N.ToString());
        P("");

        P("content of member 'name':");
        P(N["name"]);
        P("");

        P("content of member 'array':");
        P(N["array"].ToString(""));
        P("");

        P("first element of member 'array': " + N["array"][0]);
        P("");

        N["array"][0].AsInt = 10;
        P("value of the first element set to: " + N["array"][0]);
        P("The value of the first element as integer: " + N["array"][0].AsInt);
        P("");

        P("N[\"array\"][1][\"data\"] == " + N["array"][1]["data"]);
        P("");

        var data = N.SaveToBase64();
        var data2 = N.SaveToCompressedBase64();
        N = null;
        P("Serialized to Base64 string:");
        P(data);
        P("Serialized to Base64 string (compressed):");
        P(data2);
        P("");

        N = JSONNode.LoadFromBase64(data);
        P("Deserialized from Base64 string:");
        P(N.ToString());
        P("");

        var I = new JSONClass();
        I["version"].AsInt = 5;
        I["author"]["name"] = "Bunny83";
        I["author"]["phone"] = "0123456789";
        I["data"][-1] = "First item\twith tab";
        I["data"][-1] = "Second item";
        I["data"][-1]["value"] = "class item";
        I["data"].Add("Forth item");
        I["data"][1] = I["data"][1] + " 'addition to the second item'";
        I.Add("version", "1.0");

        P("Second example:");
        P(I.ToString());
        P("");

        P("I[\"data\"][0]            : " + I["data"][0]);
        P("I[\"data\"][0].ToString() : " + I["data"][0].ToString());
        P("I[\"data\"][0].Value      : " + I["data"][0].Value);
        P (I.ToString());
    }
示例#26
0
	public JSONClass toJSON(){
		JSONClass j = new JSONClass ();
		j.Add ("id", new JSONData (id));
		j.Add ("prodId", new JSONData (productId));
		j.Add ("type", new JSONData (type));
		j.Add ("quantity", new JSONData (quantity));
		return j;
	}
示例#27
0
    void Start()
    {
        SimpleJSON.JSONNode hostfile = new SimpleJSON.JSONClass();

#if !(UNITY_WEBPLAYER || UNITY_WEBGL)
        if (!System.IO.File.Exists("host.cfg"))
        {
            hostfile.Add("limesurvey_host", "localhost:4000");
        }
        else
        {
            hostfile = SimpleJSON.JSON.Parse(System.IO.File.ReadAllText("host.cfg"));
        }
#endif
        try
        {
            host                 = hostfile["limesurvey_host"];
            survey_pre           = hostfile["limesurvey_pre"];
            survey_post          = hostfile["limesurvey_post"];
            survey_tea           = hostfile["limesurvey_tea"];
            master_token_online  = hostfile["master_token_online"];
            master_token_offline = hostfile["master_token_offline"];

            activities_tracking = hostfile["activities_tracking"];
        }
        catch (Exception ex) { }

        PlayerPrefs.SetString("LimesurveyHost", host);
        if (survey_pre != "")
        {
            PlayerPrefs.SetString("LimesurveyPre", survey_pre);
            PlayerPrefs.SetString("CurrentSurvey", "pre");
        }
        if (survey_post != "")
        {
            PlayerPrefs.SetString("LimesurveyPost", survey_post);
        }
        else
        {
            PlayerPrefs.DeleteKey("LimesurveyPost");
        }

        if (survey_tea != "")
        {
            PlayerPrefs.SetString("LimesurveyTea", survey_tea);
        }
        else
        {
            PlayerPrefs.DeleteKey("LimesurveyTea");
        }

        if (master_token_online != "")
        {
            PlayerPrefs.SetString("MasterTokenOnline", master_token_online);
        }
        else
        {
            PlayerPrefs.DeleteKey("MasterTokenOnline");
        }

        if (master_token_offline != "")
        {
            PlayerPrefs.SetString("MasterTokenOffline", master_token_offline);
        }
        else
        {
            PlayerPrefs.DeleteKey("MasterTokenOffline");
        }

        PlayerPrefs.SetString("ActivitiesTracking", activities_tracking);
        if (activities_tracking == "" || activities_tracking == null)
        {
            sessionObj.ValidateSession();
        }

        PlayerPrefs.Save();
    }
示例#28
0
		public override void Add (string aKey, JSONNode aItem)
		{
			var tmp = new JSONClass ();
			tmp.Add (aKey, aItem);
			Set (tmp);
		}
示例#29
0
    private static JSONNode SaveToJSON()
    {
        JSONClass root = new JSONClass ();

        JSONArray slotsJson = new JSONArray ();
        int i =0;
        foreach (Save slotInList in saves) {
            JSONClass slot = new JSONClass();

            if(saves[i].Hero.Name != null) {
                JSONData name = new JSONData (slotInList.Hero.Name);
                slot.Add ("name", name);
                JSONData score = new JSONData (slotInList.Score);
                slot.Add ("score", score);
                JSONData heroClass = new JSONData (slotInList.Hero.GetType().ToString());
                slot.Add ("class", heroClass);
                JSONData heroXp = new JSONData (slotInList.Hero.XpQuantity);
                slot.Add ("xp", heroXp);
                JSONData currentLevel = new JSONData (GameModel.Levels[slotInList.LevelId].Name);
                slot.Add ("currentLevel", currentLevel);
            } else {
                slot.Add ("name", "");
                slot.Add ("score", "");
                slot.Add ("class", "");
                slot.Add ("xp", "");
                slot.Add ("currentLevel", "");
            }

            slotsJson.Add (slot);

            Debug.Log(i);
            i++;
        }

        root.Add ("slots", slotsJson);
        return root;
    }
示例#30
0
	//it's static so we can call it from anywhere
	public void Save() {
		Debug.Log ("SAVING");
		JSONClass newSave = new JSONClass();
		JSONArray itemSave = new JSONArray ();
		JSONArray runeSave = new JSONArray ();
		newSave.Add ("item", itemSave);
		newSave.Add ("rune", runeSave);
		newSave.Add ("discovered", new JSONData (discovered));
		for (int i = 0; i < itemUnlock.Length; i++) {
			newSave ["item"].Add(new JSONData(itemUnlock[i]));
		}
		for (int i = 0; i < runeUnlock.Length; i++) {
			newSave ["rune"].Add(new JSONData(runeUnlock[i]));
		}
		//Application.persistentDataPath is a string, so if you wanted you can put that into debug.log if you want to know where save games are located
		FileStream file = File.Create (Application.persistentDataPath + "/savedData.json"); //you can call it anything you want
		file.Close();
		System.IO.File.WriteAllText(Application.persistentDataPath + "/savedData.json", newSave.ToString(""));
	}   
示例#31
0
	public JSONClass toJSON(){
		JSONClass j = new JSONClass ();
		j.Add ("id", new JSONData (id));
		j ["attributes"] = attributes;
		j.Add ("type", new JSONData (type));
		j ["soldiers"] = soldiers.toJSON ();
		return j;
	}
示例#32
0
    void Test()
    {
        var N = SimpleJSON.JSONNode.Parse("{\"name\":\"test\", \"array\":[1,{\"data\":\"value\"}]}");

        N["array"][1]["Foo"] = "Bar";
        P("'nice formatted' string representation of the JSON tree:");
        P(N.ToString(""));
        P("");

        P("'normal' string representation of the JSON tree:");
        P(N.ToString());
        P("");

        P("content of member 'name':");
        P(N["name"]);
        P("");

        P("content of member 'array':");
        P(N["array"].ToString(""));
        P("");

        P("first element of member 'array': " + N["array"][0]);
        P("");

        N["array"][0].AsInt = 10;
        P("value of the first element set to: " + N["array"][0]);
        P("The value of the first element as integer: " + N["array"][0].AsInt);
        P("");

        P("N[\"array\"][1][\"data\"] == " + N["array"][1]["data"]);
        P("");

        var data  = N.SaveToBase64();
        var data2 = N.SaveToCompressedBase64();

        N = null;
        P("Serialized to Base64 string:");
        P(data);
        P("Serialized to Base64 string (compressed):");
        P(data2);
        P("");

        N = SimpleJSON.JSONNode.LoadFromBase64(data);
        P("Deserialized from Base64 string:");
        P(N.ToString());
        P("");

        var I = new SimpleJSON.JSONClass();

        I["version"].AsInt     = 5;
        I["author"]["name"]    = "Bunny83";
        I["author"]["phone"]   = "0123456789";
        I["data"][-1]          = "First item\twith tab";
        I["data"][-1]          = "Second item";
        I["data"][-1]["value"] = "class item";
        I["data"].Add("Forth item");
        I["data"][1] = I["data"][1] + " 'addition to the second item'";
        I.Add("version", "1.0");

        P("Second example:");
        P(I.ToString());
        P("");

        P("I[\"data\"][0]            : " + I["data"][0]);
        P("I[\"data\"][0].ToString() : " + I["data"][0].ToString());
        P("I[\"data\"][0].Value      : " + I["data"][0].Value);
        P(I.ToString());
    }
示例#33
0
        public static JSONNode Deserialize(System.IO.BinaryReader aReader)
        {
            JSONBinaryTag type = (JSONBinaryTag)aReader.ReadByte();

            switch (type)
            {
            case JSONBinaryTag.Array:
            {
                int       count = aReader.ReadInt32();
                JSONArray tmp   = new JSONArray();
                for (int i = 0; i < count; i++)
                {
                    tmp.Add(Deserialize(aReader));
                }
                return(tmp);
            }

            case JSONBinaryTag.Class:
            {
                int       count = aReader.ReadInt32();
                JSONClass tmp   = new JSONClass();
                for (int i = 0; i < count; i++)
                {
                    string key = aReader.ReadString();
                    var    val = Deserialize(aReader);
                    tmp.Add(key, val);
                }
                return(tmp);
            }

            case JSONBinaryTag.Value:
            {
                return(new JSONData(aReader.ReadString()));
            }

            case JSONBinaryTag.IntValue:
            {
                return(new JSONData(aReader.ReadInt32()));
            }

            case JSONBinaryTag.DoubleValue:
            {
                return(new JSONData(aReader.ReadDouble()));
            }

            case JSONBinaryTag.BoolValue:
            {
                return(new JSONData(aReader.ReadBoolean()));
            }

            case JSONBinaryTag.FloatValue:
            {
                return(new JSONData(aReader.ReadSingle()));
            }

            default:
            {
                throw new Exception("Error deserializing JSON. Unknown tag: " + type);
            }
            }
        }
示例#34
0
        public static JSONNode Deserialize(BinaryReader aReader)
        {
            var type = (JSONBinaryTag)aReader.ReadByte();

            switch (type)
            {
            case JSONBinaryTag.Array:
            {
                var count = aReader.ReadInt32();
                var tmp   = new JSONArray();
                for (var i = 0; i < count; i++)
                {
                    tmp.Add(Deserialize(aReader));
                }
                return(tmp);
            }

            case JSONBinaryTag.Class:
            {
                var count = aReader.ReadInt32();
                var tmp   = new JSONClass();
                for (var i = 0; i < count; i++)
                {
                    var key = aReader.ReadString();
                    var val = Deserialize(aReader);
                    tmp.Add(key, val);
                }
                return(tmp);
            }

            case JSONBinaryTag.Value:
            {
                return(new JSONData(aReader.ReadString()));
            }

            case JSONBinaryTag.IntValue:
            {
                return(new JSONData(aReader.ReadInt32()));
            }

            case JSONBinaryTag.DoubleValue:
            {
                return(new JSONData(aReader.ReadDouble()));
            }

            case JSONBinaryTag.BoolValue:
            {
                return(new JSONData(aReader.ReadBoolean()));
            }

            case JSONBinaryTag.FloatValue:
            {
                return(new JSONData(aReader.ReadSingle()));
            }

            case JSONBinaryTag.LongValue:
            {
                return(new JSONData(aReader.ReadInt64()));
            }

            case JSONBinaryTag.Null:
            {
                return(new JSONData(null));
            }
            }

            throw new Exception("JSON Deserialize: Unknown tag in stream");
        }
示例#35
0
    private static JSONNode HighScoreToJSON()
    {
        JSONClass root = new JSONClass ();

        JSONArray slotsJson = new JSONArray ();
        foreach (HighScore slotInList in highScores) {
            JSONClass slot = new JSONClass();

            JSONData name = new JSONData (slotInList.Name);
            slot.Add ("name", name);

            JSONData score = new JSONData (slotInList.Score);
            slot.Add ("score", score);

            slotsJson.Add (slot);
        }

        root.Add ("slots", slotsJson);
        return root;
    }
示例#36
0
        /*
         * {
                "type": "group_info", //标记
                "group": //group 信息
                 {
                    "member":
                    [//成员
                        {
                            "uid": ""//用户id
                        },
                        ...
                    ],
                    "vid": "", //场馆id
                    "name": "",//..名字
                    "address": "",//..地址
                    "time": "",//..时间
                    "latitude": "",//..经度
                    "longtitude": "",//..纬度
                    "state": "",//..状态 3种状态 0 是未预订 2是预订 1是投票状态
                    "max": ""//..最大成员数 默认10
                }
            }
         */
        public string GetExtJson(string groupID)
        {
            Monitor.Enter(userGroupDict);
            try
            {
                SportMatchGroup group = groupList.Find(a => { return a.groupID == groupID; });
                Venue venue = group.venue;

                JSONClass jc = new JSONClass();
                jc.Add("type", new JSONData("group_info"));
                JSONClass jc_1 = new JSONClass();
                JSONArray ja_1_1 = new JSONArray();
                var itr = userGroupDict.GetEnumerator();
                while (itr.MoveNext())
                {
                    string groupid = itr.Current.Value;
                    if (groupid != groupID)
                        continue;
                    string uuid = itr.Current.Key;
                    JSONClass jc_1_1_i = new JSONClass();
                    jc_1_1_i.Add("uid", new JSONData(uuid));
                    ja_1_1.Add(jc_1_1_i);
                }
                jc_1.Add("member", ja_1_1);
                if (venue == null)
                {
                    jc_1.Add("vid", new JSONData(""));
                    jc_1.Add("name", new JSONData(""));
                    jc_1.Add("address", new JSONData(""));
                    jc_1.Add("time", new JSONData(""));
                    jc_1.Add("latitude", new JSONData(""));
                    jc_1.Add("longtitude", new JSONData(""));
                    jc_1.Add("state", new JSONData(0));
                }
                else
                {
                    jc_1.Add("vid", new JSONData(venue.id));
                    jc_1.Add("name", new JSONData(venue.name));
                    jc_1.Add("address", new JSONData(venue.address));
                    jc_1.Add("time", new JSONData(venue.time));
                    jc_1.Add("latitude", new JSONData(venue.latitude));
                    jc_1.Add("longtitude", new JSONData(venue.longitude));
                    jc_1.Add("state", new JSONData(2));
                }
                jc_1.Add("max", new JSONData(10));
                jc.Add("group", jc_1);
                return jc.ToJSON(0);
            }
            finally
            {
                Monitor.Exit(userGroupDict);
            }
        }
示例#37
0
	public JSONClass toJSON(){
		JSONClass j = new JSONClass ();
		j.Add ("id", new JSONData (id));
		j ["attributes"] = attributes;
		j.Add ("type", new JSONData (type));
		j.Add ("quantity", new JSONData (quantity));
		j ["weapons"] = weapons.toJSON ();
		j ["armors"] = armors.toJSON ();
		j ["shields"] = shields.toJSON ();
		return j;
	}
示例#38
0
	public JSONClass toJSON(){
		JSONClass j = new JSONClass ();
		j.Add ("id", new JSONData (id));
		j.Add ("type", new JSONData (type));
		j.Add ("targetId", new JSONData (targetId));
		j ["startTimestamp"] = startTimestamp.ToString();
		j ["etaTimestamp"] = etaTimestamp.ToString();
		return j;
	}
示例#39
0
	public JSONClass toJSON(){
		JSONClass j = new JSONClass ();
		j.Add ("id", new JSONData (id));
		j.Add ("type", new JSONData (type));
		j.Add ("level", new JSONData (level));
		return j;
	}
示例#40
0
    void OnGUI()
    {
        GUI.skin = activeSkin;

        scrollPosition = GUI.BeginScrollView(containerRect, scrollPosition, innerFrameRect);

        if (!String.IsNullOrEmpty(error))
        {
            GUI.Label(label_AlertRect, error, alertMsgStyle);
        }

        GUI.Label(headerRect, header, headerStyle);

        GUI.Label(label_Feedback1Rect, question_1, labelStyle);
        feedback_1 = GUI.TextArea(txtArea_Feedback1, feedback_1);

        GUI.Label(label_Feedback2Rect, question_2, labelStyle);
        feedback_2 = GUI.TextArea(txtArea_Feedback2, feedback_2);

        GUI.Label(label_Feedback3Rect, question_3, labelStyle);
        feedback_3 = GUI.TextArea(txtArea_Feedback3, feedback_3);

        GUI.Label(label_Feedback4Rect, question_4, labelStyle);
        feedback_4 = GUI.TextArea(txtArea_Feedback4, feedback_4);

        GUI.Label(label_RateRect, label_rate, labelStyle);
        GUILayout.BeginArea(radioBtnRect);
        GUILayout.BeginHorizontal();
        GUILayout.FlexibleSpace();
        toolbarInt = GUILayout.Toolbar(toolbarInt, toolbarStrings, radioBtnStyle);
        GUILayout.FlexibleSpace();
        GUILayout.EndHorizontal();
        GUILayout.EndArea();
        //toolbarInt = GUI.Toolbar(radioBtnRect,toolbarInt, toolbarStrings, radioBtnStyle);

        if (GUI.Button(A_btnRect, "main menu", A_btnStyle))
        {
            // Open Contact us modal
            Application.LoadLevel("GUI_TitleScreen");
        }

        // Submit
        if (GUI.Button(B_btnRect, "submit", B_btnStyle))
        {
            // Clear Error message
            error = String.Empty;

            #region Validate fields
            // Check if any field is empty
            if (String.IsNullOrEmpty(feedback_1) ||
                String.IsNullOrEmpty(feedback_2) ||
                String.IsNullOrEmpty(feedback_3) ||
                String.IsNullOrEmpty(feedback_4))
            {
                if (!String.IsNullOrEmpty(error))
                {
                    error += "\n";
                }
                error   += "Please fill in all fields :)";
                newAlert = true;
            }
            #endregion
            #region Format and send
            if (String.IsNullOrEmpty(error))
            {
                // Package the review
                SimpleJSON.JSONClass json = new SimpleJSON.JSONClass();
                json.Add("Device id", deviceId);
                json.Add("Likes", feedback_1);
                json.Add("Hates", feedback_2);
                json.Add("Suggestions", feedback_3);
                json.Add("Other", feedback_4);
                json.Add("Rating", (toolbarInt + 1).ToString());

                // Do something...
                storageService.InsertJSONDocument(Constants.dbName, Constants.collectionReviews, json, callBack);

                // Log the event
                logService.SetEvent("[DEMO] Feedback Submitted", logCallBack);

                error    = "Sending...";
                newAlert = true;
            }
            #endregion
        }

        A_btnScale.OnMouseOver(A_btnRect);
        B_btnScale.OnMouseOver(B_btnRect);
        GUI.EndScrollView();
        //DemoReviewForm();
    }
示例#41
0
	public JSONClass toJSON(){
		JSONClass j = new JSONClass ();
		j.Add ("id", new JSONData (id));
		j.Add ("attackerId", new JSONData (attackerId));
		j ["timestamp"] = timestamp.ToString();
		j.Add ("attackerGeneral", new JSONData (attackerGeneral));
		j.Add ("defenderkerGeneral", new JSONData (defenderGeneral));
		j.Add ("result", new JSONData (result));
		return j;
	}
示例#42
0
		public override JSONNode this [string aKey]
		{
			get {
				return new JSONLazyCreator (this, aKey);
			}
			set {
				var tmp = new JSONClass ();
				tmp.Add (aKey, value);
				Set (tmp);
			}
		}
示例#43
0
	public JSONClass toJSON(){
		JSONClass j = new JSONClass ();
		j.Add ("id", new JSONData (id));
		j ["timestamp"] = timestamp.ToString();
		j.Add ("senderId", new JSONData (senderId));
		j ["message"] = message;
		j.Add ("isTo", new JSONData (isTo));
		return j;
	}
示例#44
0
		public static JSONNode Deserialize (System.IO.BinaryReader aReader)
		{
			JSONBinaryTag type = (JSONBinaryTag)aReader.ReadByte ();
			switch (type) {
			case JSONBinaryTag.Array:
			{
				int count = aReader.ReadInt32 ();
				JSONArray tmp = new JSONArray ();
				for (int i = 0; i < count; i++)
					tmp.Add (Deserialize (aReader));
				return tmp;
			}
			case JSONBinaryTag.Class:
			{
				int count = aReader.ReadInt32 ();                
				JSONClass tmp = new JSONClass ();
				for (int i = 0; i < count; i++) {
					string key = aReader.ReadString ();
					var val = Deserialize (aReader);
					tmp.Add (key, val);
				}
				return tmp;
			}
			case JSONBinaryTag.Value:
			{
				return new JSONData (aReader.ReadString ());
			}
			case JSONBinaryTag.IntValue:
			{
				return new JSONData (aReader.ReadInt32 ());
			}
			case JSONBinaryTag.DoubleValue:
			{
				return new JSONData (aReader.ReadDouble ());
			}
			case JSONBinaryTag.BoolValue:
			{
				return new JSONData (aReader.ReadBoolean ());
			}
			case JSONBinaryTag.FloatValue:
			{
				return new JSONData (aReader.ReadSingle ());
			}
				
			default:
			{
				throw new Exception ("Error deserializing JSON. Unknown tag: " + type);
			}
			}
		}
示例#45
0
 public override void Add (string aKey, JSONNode aItem)
 {
     var tmp = new JSONClass();
     tmp.Add(aKey, aItem);
     Set(tmp);
 }