本文整理汇总了C#中JSONObject.ContainsKey方法的典型用法代码示例。如果您正苦于以下问题:C# JSONObject.ContainsKey方法的具体用法?C# JSONObject.ContainsKey怎么用?C# JSONObject.ContainsKey使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类JSONObject
的用法示例。
在下文中一共展示了JSONObject.ContainsKey方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: UpdateRowData
public void UpdateRowData(JSONObject data) {
rowData = data;
leftUserData = data.GetObject("left");
if (data.ContainsKey("right")) {
rightUserData = data.GetObject("right");
} else {
rightUserData = null;
}
if (leftUserData != null) {
Utils.SetActive(leftUser, true);
leftUsernameLabel.text = leftUserData.GetString("displayName");
leftCheckbox.value = leftCheckboxState;
EventDelegate.Set(leftCheckboxListener.onClick, delegate() { EventCheckboxChanged(true); });
} else {
Utils.SetActive(leftUser, false);
}
if (rightUserData != null) {
Utils.SetActive(rightUser, true);
rightUsernameLabel.text = rightUserData.GetString("displayName");
rightCheckbox.value = rightCheckboxState;
EventDelegate.Set(rightCheckboxListener.onClick, delegate() { EventCheckboxChanged(false); });
} else {
Utils.SetActive(rightUser, false);
}
}
示例2: UpdateSeats
public override void UpdateSeats(JSONObject jsonData) {
JSONArray userList = jsonData.GetObject("gameRoom").GetArray("userGames");
users = new JSONObject();
for (int i = 0 ; i < userList.Length; i++) {
users.Add(userList[i].Obj.GetInt("seatIndex").ToString(), userList[i].Obj);
}
// FAKE user joined
for (int i = 0; i < 4; i++) {
GameObject tempUser;
PlayerSlotScript playerScript = playerHolder[i];
JSONObject user = users.ContainsKey(i.ToString()) ? users.GetObject(i.ToString()) : null;
if (user != null) {
playerScript.Init(user.GetString("userId"), "Dan Choi" + (i + 1), (i + 1) * 200000, string.Empty);
} else {
playerScript.InitEmpty();
}
}
}
示例3: update
public void update(JSONObject json, bool all = false)
{
is_connected = true;
id = (int)json.GetNumber("id");
username = json.GetString("username");
email = json.GetString("email");
score = (int)json.GetNumber("score");
room = json.GetString("room");
if (!json.ContainsKey("friends"))
{
this.friends = new Friends();
return;
} // Info private
phi = (int)json.GetNumber("phi");
if (all)
ProcessSwungMens(json.GetArray("swungmens"));
// -- Friends
JSONArray friends = json.GetArray("friends");
this.friends = new Friends(friends);
}
示例4: SpinData
public SpinData(string username, JSONObject jsonData, bool isYou) {
Debug.Log("SpinData: " + jsonData.ToString());
this.isYou = isYou;
this.username = username;
JSONArray resultsData = jsonData.GetArray("items");
JSONObject extraData = SlotCombination.CalculateCombination(resultsData, jsonData.GetInt("nL"));
JSONArray winningCount = extraData.GetArray("wCount");
JSONArray winningType = extraData.GetArray("wType");
JSONArray winningGold = jsonData.GetArray("wGold");
for (int i = 0; i < winningGold.Length; i++) {
totalDamage += (int)winningGold[i].Number;
}
if (jsonData.ContainsKey("newBoss")) {
newBossData = jsonData.GetObject("newBoss");
JSONArray bossDrops = jsonData.GetArray("dropItems");
dropCash = (int)bossDrops[0].Number;
dropGem = (int)bossDrops[1].Number;
bossDrops = null;
AccountManager.Instance.bossKilled++;
}
for (int i = 0; i < winningCount.Length; i++) {
if (winningCount[i].Number >= 3 || ((int)winningType[i].Number == (int)SlotItem.Type.TILE_1 && winningCount[i].Number >= 2)) {
spawnSkills.Add(new SpawnableSkill((int)winningType[i].Number, (int)winningCount[i].Number, (int)winningGold[i].Number, isYou));
}
}
extraData = null;
resultsData = null;
winningCount = null;
winningType = null;
winningGold = null;
}
示例5: Start
void Start()
{
infoText.gameObject.SetActive(false);
//JSONObject usage example:
//Parse string into a JSONObject:
JSONObject.Parse(stringToEvaluate);
//You can also create an "empty" JSONObject
JSONObject emptyObject = new JSONObject();
//Adding values is easy (values are implicitly converted to JSONValues):
emptyObject.Add("key", "value");
emptyObject.Add("otherKey", 123);
emptyObject.Add("thirdKey", false);
emptyObject.Add("fourthKey", new JSONValue(JSONValueType.Null));
//You can iterate through all values with a simple for-each loop
foreach (KeyValuePair<string, JSONValue> pair in emptyObject) {
Debug.Log("key : value -> " + pair.Key + " : " + pair.Value);
//Each JSONValue has a JSONValueType that tells you what type of value it is. Valid values are: String, Number, Object, Array, Boolean or Null.
Debug.Log("pair.Value.Type.ToString() -> " + pair.Value.Type.ToString());
if (pair.Value.Type == JSONValueType.Number) {
//You can access values with the properties Str, Number, Obj, Array and Boolean
Debug.Log("Value is a number: " + pair.Value.Number);
}
}
//JSONObject's can also be created using this syntax:
JSONObject newObject = new JSONObject {{"key", "value"}, {"otherKey", 123}, {"thirdKey", false}};
//JSONObject overrides ToString() and outputs valid JSON
Debug.Log("newObject.ToString() -> " + newObject.ToString());
//JSONObjects support array accessors
Debug.Log("newObject[\"key\"].Str -> " + newObject["key"].Str);
//It also has a method to do the same
Debug.Log("newObject.GetValue(\"otherKey\").ToString() -> " + newObject.GetValue("otherKey").ToString());
//As well as a method to determine whether a key exists or not
Debug.Log("newObject.ContainsKey(\"NotAKey\") -> " + newObject.ContainsKey("NotAKey"));
//Elements can removed with Remove() and the whole object emptied with Clear()
newObject.Remove("key");
Debug.Log("newObject with \"key\" removed: " + newObject.ToString());
newObject.Clear();
Debug.Log("newObject cleared: " + newObject.ToString());
}
示例6: ImportBaseData
protected void ImportBaseData(JSONObject json_data)
{
m_progression_idx = (int) json_data["m_progression"].Number;
m_ease_type = (EasingEquation) (int) json_data["m_ease_type"].Number;
m_is_offset_from_last = json_data["m_is_offset_from_last"].Boolean;
m_to_to_bool = json_data["m_to_to_bool"].Boolean;
m_unique_randoms = json_data["m_unique_randoms"].Boolean;
m_animate_per = (AnimatePerOptions) (int) json_data["m_animate_per"].Number;
m_override_animate_per_option = json_data["m_override_animate_per_option"].Boolean;
if(json_data.ContainsKey("m_custom_ease_curve"))
m_custom_ease_curve = json_data["m_custom_ease_curve"].Array.JSONtoAnimationCurve();
}
示例7: ImportData
public override void ImportData(JSONObject json_data)
{
base.ImportData(json_data);
m_force_position_override = json_data["m_force_position_override"].Boolean;
if(json_data.ContainsKey("m_bezier_curve"))
{
m_bezier_curve.ImportData(json_data["m_bezier_curve"].Obj);
}
}
示例8: ImportData
public void ImportData(JSONObject json_data)
{
m_letters_to_animate = json_data["m_letters_to_animate"].Array.JSONtoListInt();
m_letters_to_animate_custom_idx = (int)json_data["m_letters_to_animate_custom_idx"].Number;
m_letters_to_animate_option = (LETTERS_TO_ANIMATE)(int)json_data["m_letters_to_animate_option"].Number;
m_loop_cycles = new List<ActionLoopCycle>();
if (json_data.ContainsKey("LOOPS_DATA"))
{
ActionLoopCycle loop_cycle;
foreach (var loop_data in json_data["LOOPS_DATA"].Array)
{
loop_cycle = new ActionLoopCycle();
loop_cycle.ImportData(loop_data.Obj);
m_loop_cycles.Add(loop_cycle);
}
}
m_letter_actions = new List<LetterAction>();
LetterAction letter_action;
foreach (var action_data in json_data["ACTIONS_DATA"].Array)
{
letter_action = new LetterAction();
letter_action.ImportData(action_data.Obj);
m_letter_actions.Add(letter_action);
}
}
示例9: LoadMatches
private void LoadMatches()
{
FileInfo summaryFile = new FileInfo(App.SummaryPath);
var dir = new DirectoryInfo(App.Rootpath);
if (!dir.Exists) dir.Create();
Logger.WriteLine("Loading replays from {0}", App.Rootpath);
FileStream loadSummary;
if (!summaryFile.Exists) loadSummary = summaryFile.Create();
else loadSummary = summaryFile.Open(FileMode.Open);
var mems = new MemoryStream();
loadSummary.CopyTo(mems);
loadSummary.Close();
dynamic summary;
try {
summary = MFroehlich.Parsing.MFro.MFroFormat.Deserialize(mems.ToArray());
Logger.WriteLine("Loaded {0} summaries from {1}", summary.Count, summaryFile.FullName);
} catch (Exception x) {
summary = new JSONObject();
Logger.WriteLine(Priority.Error, "Error loading summaries {0}, starting new summary list", x.Message);
}
dynamic newSummary = new JSONObject();
List<FileInfo> files = new DirectoryInfo(App.Rootpath).EnumerateFiles("*.lol").ToList();
files.Sort((a, b) => b.Name.CompareTo(a.Name));
int summaries = 0;
var timer = new System.Diagnostics.Stopwatch(); timer.Start();
for (int i = 0; i < files.Count; i++) {
string filename = files[i].Name.Substring(0, files[i].Name.Length - 4);
ReplayItem item;
if (summary.ContainsKey(filename)) {
item = new ReplayItem((SummaryData) summary[filename], files[i]);
newSummary.Add(filename, summary[filename]);
} else {
SummaryData data = new SummaryData(new MFroReplay(files[i]));
newSummary.Add(filename, JSONObject.From(data));
item = new ReplayItem(data, files[i]);
summaries++;
}
item.MouseUp += OpenDetails;
replays.Add(item);
}
Logger.WriteLine("All replays loaded, took {0}ms", timer.ElapsedMilliseconds);
using (FileStream saveSummary = summaryFile.Open(FileMode.Open)) {
byte[] summBytes = MFroehlich.Parsing.MFro.MFroFormat.Serialize(newSummary);
saveSummary.Write(summBytes, 0, summBytes.Length);
Logger.WriteLine("Saved summaries, {0} total summaries, {1} newly generated", newSummary.Count, summaries);
}
Search();
ReplayArea.Visibility = System.Windows.Visibility.Visible;
LoadArea.Visibility = System.Windows.Visibility.Hidden;
Console.WriteLine("DONE");
}
示例10: Deserialize
public override void Deserialize(JSONObject obj)
{
mName = obj.GetString(NAME);
mGender = (CharacterGender)(int)obj.GetNumber(GENDER);
mExperience = (int)obj.GetNumber(EXPERIENCE);
mAvatar = obj.GetString(AVATAR);
mAlignment = (DnDAlignment)(int)obj.GetNumber(ALIGNMENT);
mRace = (DnDRace)(int)obj.GetNumber(RACE);
mAge = (int)obj.GetNumber(AGE);
if (obj.ContainsKey(DEITY))
{
mDeity = new DnDDeity();
mDeity.Deserialize(obj.GetObject(DEITY));
}
mSize = (DnDCharacterSize)(int)obj.GetNumber(SIZE);
// souls:
JSONObject jSouls = obj.GetObject(CLASS_SOULS);
var classes = Enum.GetValues(typeof(DnDCharClass)).Cast<DnDCharClass>();
foreach (DnDCharClass charClass in classes)
{
if (jSouls.ContainsKey(charClass.ToString()))
{
if (!string.IsNullOrEmpty(jSouls.GetObject(charClass.ToString()).ToString()))
{
DnDClassSoul newSoul = null;
switch (charClass)
{
case DnDCharClass.Wizard:
newSoul = new DnDWizard(this);
break;
default:
break;
}
if (newSoul != null)
{
newSoul.Deserialize(jSouls.GetObject(charClass.ToString()));
mClasses.Add(newSoul);
}
}
}
}
// abilities:
JSONArray tempArray = obj.GetArray(ABILITIES);
foreach (var val in tempArray)
{
mAbilities[(DnDAbilities)((int)val.Array[0].Number)] = (int)val.Array[1].Number;
}
}
示例11: ImportData
public void ImportData(JSONObject jsonData)
{
m_setting_name = jsonData ["name"].Str;
m_data_type = (ANIMATION_DATA_TYPE) ((int) jsonData ["data_type"].Number);
m_animation_idx = (int) jsonData ["anim_idx"].Number;
m_action_idx = (int) jsonData ["action_idx"].Number;
if(jsonData.ContainsKey("startState"))
m_startState = jsonData["startState"].Boolean;
}
示例12: getResultForWemePush
// wemePush urlscheme parse
public JSONObject getResultForWemePush(string scheme,string host,JSONObject jsonObject){
host = host.ToLower();
switch(host){
case "isallowpushmessage":
JSONObject pushallowResult = JSONObject.Parse(((TextAsset)Resources.Load("JSONRequests/"+scheme+"/"+host)).text);
pushallowResult.Remove("allow");
pushallowResult.Add("allow",onPush);
return pushallowResult;
case "requestallowpushmessage":
if(jsonObject.ContainsKey("allow")){
JSONObject requestPushResult = JSONObject.Parse(((TextAsset)Resources.Load("JSONRequests/"+scheme+"/"+host)).text);
onPush = jsonObject.GetBoolean("allow");
requestPushResult.Remove("allow");
requestPushResult.Add("allow",onPush);
return requestPushResult;
}else{
return jsonResultForError("WmInterfaceBroker",(long)WemeManager.WemeErrType.WM_ERR_INVALID_PARAMETER,"invalid_parameter",scheme+"://"+host);
}
}
return jsonResultForError("WmInterfaceBroker",(long)WemeManager.WemeErrType.WM_ERR_INVALID_PARAMETER,"invalid_parameter",scheme+"://"+host);
}
示例13: getResultForWemeOAuth
// wemeOauth urlscheme parse
private JSONObject getResultForWemeOAuth(string scheme,string host,JSONObject jsonObject){
host = host.ToLower();
switch(host){
case "loginfacebook":
if(jsonObject.ContainsKey("appId")&&jsonObject.ContainsKey("redirectUri")&&jsonObject.ContainsKey("permissions")){
JSONObject facebookResult = JSONObject.Parse(((TextAsset)Resources.Load("JSONRequests/"+scheme+"/"+host)).text);
return facebookResult;
}else{
return jsonResultForError("WmInterfaceBroker",(long)WemeManager.WemeErrType.WM_ERR_INVALID_PARAMETER,"invalid_parameter",scheme+"://"+host);
}
case "logintwitter":
if(jsonObject.ContainsKey("consumerKey")&&jsonObject.ContainsKey("consumerSecret")&&jsonObject.ContainsKey("callbackUrl")){
JSONObject twitterResult = JSONObject.Parse(((TextAsset)Resources.Load("JSONRequests/"+scheme+"/"+host)).text);
return twitterResult;
}else{
return jsonResultForError("WmInterfaceBroker",(long)WemeManager.WemeErrType.WM_ERR_INVALID_PARAMETER,"invalid_parameter",scheme+"://"+host);
}
case "loginweme":
if(jsonObject.ContainsKey("clientId")&&jsonObject.ContainsKey("clientSecret")){
JSONObject wemeResult = JSONObject.Parse(((TextAsset)Resources.Load("JSONRequests/"+scheme+"/"+host)).text);
return wemeResult;
}else{
return jsonResultForError("WmInterfaceBroker",(long)WemeManager.WemeErrType.WM_ERR_INVALID_PARAMETER,"invalid_parameter",scheme+"://"+host);
}
default:
break;
}
return jsonResultForError("WmInterfaceBroker",(long)WemeManager.WemeErrType.WM_ERR_INVALID_PARAMETER,"invalid_parameter",scheme+"://"+host);
}
示例14: getResultForWeme
// weme urlscheme parse
private JSONObject getResultForWeme(string scheme,string host,JSONObject jsonObject){
host = host.ToLower();
switch(host){
case "start":
if(jsonObject.ContainsKey("serverZone")&&jsonObject.ContainsKey("gameCode")&&jsonObject.ContainsKey("domain")&&jsonObject.ContainsKey("gameVersion")&&jsonObject.ContainsKey("marketCode")){
JSONObject jsonResult = JSONObject.Parse(((TextAsset)Resources.Load("JSONRequests/"+scheme+"/"+host)).text);
onStart=true;
return jsonResult;
}else{
return jsonResultForError("WmInterfaceBroker",(long)WemeManager.WemeErrType.WM_ERR_INVALID_PARAMETER,"invalid_parameter",scheme+"://"+host);
}
case "gateinfo":
JSONObject gateResult = JSONObject.Parse(((TextAsset)Resources.Load("JSONRequests/"+scheme+"/"+host)).text);
return gateResult;
case "isauthorized":
JSONObject authResult = JSONObject.Parse(((TextAsset)Resources.Load("JSONRequests/"+scheme+"/"+host)).text);
authResult.Remove("authorized");
authResult.Add("authorized",onLogin);
return authResult;
case "login":
if(jsonObject.ContainsKey("authData")){
JSONObject jsonResult = JSONObject.Parse(((TextAsset)Resources.Load("JSONRequests/"+scheme+"/"+host)).text);
onLogin=true;
return jsonResult;
}else{
return jsonResultForError("WmInterfaceBroker",(long)WemeManager.WemeErrType.WM_ERR_INVALID_PARAMETER,"invalid_parameter",scheme+"://"+host);
}
case "playerkey":
JSONObject playerKeyResult = JSONObject.Parse(((TextAsset)Resources.Load("JSONRequests/"+scheme+"/"+host)).text);
return playerKeyResult;
case "logout":
JSONObject logoutResult = JSONObject.Parse(((TextAsset)Resources.Load("JSONRequests/"+scheme+"/"+host)).text);
return logoutResult;
case "withdraw":
JSONObject withdrawResult = JSONObject.Parse(((TextAsset)Resources.Load("JSONRequests/"+scheme+"/"+host)).text);
return withdrawResult;
case "gameid":
JSONObject gameidResult = JSONObject.Parse(((TextAsset)Resources.Load("JSONRequests/"+scheme+"/"+host)).text);
return gameidResult;
case "request":
if(jsonObject.ContainsKey("uri")){
JSONObject jsonResult = JSONObject.Parse(((TextAsset)Resources.Load("JSONRequests/"+scheme+"/"+host)).text);
onLogin=true;
return jsonResult;
}else{
return jsonResultForError("WmInterfaceBroker",(long)WemeManager.WemeErrType.WM_ERR_INVALID_PARAMETER,"invalid_parameter",scheme+"://"+host);
}
case "configuration":
JSONObject configurationResult = JSONObject.Parse(((TextAsset)Resources.Load("JSONRequests/"+scheme+"/"+host)).text);
return configurationResult;
case "authdata":
JSONObject authdataResult = JSONObject.Parse(((TextAsset)Resources.Load("JSONRequests/"+scheme+"/"+host)).text);
return authdataResult;
case "sdkversion":
JSONObject sdkversionResult = JSONObject.Parse(((TextAsset)Resources.Load("JSONRequests/"+scheme+"/"+host)).text);
return sdkversionResult;
}
return jsonResultForError("WmInterfaceBroker",(long)WemeManager.WemeErrType.WM_ERR_INVALID_PARAMETER,"invalid_parameter",scheme+"://"+host);
}