コード例 #1
0
	IEnumerator lmsLoadData( string path, LMSLoadDataCallback callback )
	{
		// make JSON
		JSONObject j = new JSONObject(JSONObject.Type.OBJECT);
		//number
		j.AddField("action", "AppData_DataDump");
		// make param area
		JSONObject arr = new JSONObject(JSONObject.Type.ARRAY);
		j.AddField("params", arr);
		// add params
		arr.AddField ("key",path);
		// add authkey
		string keyNoQuotes = pingAuthKey.Replace ("\"","");
		j.AddField ("authKey",keyNoQuotes);
		// get the string
		string bodyString = j.print();

		LMSDebug ("LMSIntegration.lmsLoadData(" + path + ") : bodystring=<" + bodyString + ">");
		
		// Create a download object
		string url = "http://" + URL + "statefull/get";
		WWW download = new WWW(url,Encoding.ASCII.GetBytes(bodyString),pingHeaders); 
		yield return download;
		
		string DBResult;
		string DBErrorString;
		
		if (download.error != null) 
		{
			// save the error
			DBResult = "";
			DBErrorString = download.error;
			// decode return
			JSONObject decoder = new JSONObject(download.text);
			JSONObject msg = decoder.GetField ("msg");
			UnityEngine.Debug.LogError("LMSIntegration.lmsLoadData() : error, msg=" + msg.print());
			// bad return
			if ( callback != null )
				callback(null,download); 
		}
		else
		{
			// decode
			JSONObject decoder = new JSONObject(download.text);
			if ( CheckReturn(decoder) == true )
			{
				JSONObject p = decoder.GetField ("params");
				if ( p != null && p.list != null )
				{
					List<string> returnData = new List<string>();
					foreach( JSONObject o in p.list )
					{
						JSONObject k = o.GetField("key");
						JSONObject d = o.GetField("data");
						UnityEngine.Debug.LogError("key=" + k.print() + " : data=" + d.print());
						returnData.Add (d.print());
					}
					if ( callback != null )
						callback(returnData,download);
				}
			}
			else
			{
				// probably an error, show it
				JSONObject p = decoder.GetField ("params");
				JSONObject msg = p.GetField("msg");
				if ( msg != null )
				{
					UnityEngine.Debug.LogError("LMSIntegration.lmsLoadData() : msg=" + msg.print ());
					// bad return
					if ( callback != null )
						callback(null,download);
				}
			}
			
			DBResult = "ok";
			
		}
	}
コード例 #2
0
	public void LMSLoadData( string path, LMSLoadDataCallback callback )
	{
		StartCoroutine(lmsLoadData(path,callback));
	}