JSONObject.HasFields C# (CSharp) Method

HasFields() public method

public HasFields ( string names ) : bool
names string
return bool
	public bool HasFields(string[] names)
	{
		for (int i = 0; i < names.Length; i++)
			if (!keys.Contains(names[i]))
				return false;
		return true;
	}
	public bool HasField(string name)

Usage Example

Example #1
0
        /// <summary>
        /// Reconstructs the <see cref="CloudConfig"/> from a <see cref="JSONObject"/>.
        /// </summary>
        /// <param name="jsonObject"><see cref="JSONObject"/> containing the <see cref="CloudConfig"/>.</param>
        private void FromJSONObject(JSONObject jsonObject)
        {
            if (!jsonObject.HasFields(achievementIDsName, leaderboardIDsName, cloudVariablesName, appleSupportedName, googleSupportedName,
                                      amazonSupportedName, androidPlatformName, googleAppIDName, googleSetupRunName, debugModeEnabledName, versionName))
            {
                throw new SerializationException("JSONObject missing fields, cannot deserialize to " + typeof(CloudConfig).Name);
            }

            AchievementIDs   = EditorJsonHelper.Convert <List <PlatformIdData> >(jsonObject[achievementIDsName]);
            LeaderboardIDs   = EditorJsonHelper.Convert <List <PlatformIdData> >(jsonObject[leaderboardIDsName]);
            CloudVariables   = EditorJsonHelper.Convert <List <CloudVariableData> >(jsonObject[cloudVariablesName]);
            AppleSupported   = jsonObject[appleSupportedName].B;
            GoogleSupported  = jsonObject[googleSupportedName].B;
            AmazonSupported  = jsonObject[amazonSupportedName].B;
            AndroidPlatform  = (AndroidBuildPlatform)Enum.Parse(typeof(AndroidBuildPlatform), jsonObject[androidPlatformName].String);
            GoogleAppID      = jsonObject[googleAppIDName].String;
            GoogleSetupRun   = jsonObject[googleSetupRunName].B;
            DebugModeEnabled = jsonObject[debugModeEnabledName].B;
            Version          = jsonObject[versionName].String;
            if (jsonObject.HasFields(apiKeyName))
            {
                ApiKey = jsonObject[apiKeyName].String;
            }

            if (jsonObject.HasFields(settingsLocationName))
            {
                SettingsLocation = (SettingsLocation)Enum.Parse(typeof(SettingsLocation), jsonObject[settingsLocationName].String);
            }
        }
All Usage Examples Of JSONObject::HasFields