Пример #1
0
        public string BuildPayload(string serviceFlagName, bool status)
        {
            const string payloadFieldName = "service_flags";

            // A Dictionary is used here because both the key and the value must be mutable.
            // The key is the the service flag name and the value is the status bool.
            var serviceFlags = new Dictionary <string, bool>
            {
                [serviceFlagName] = status,
            };

            var payload = new Dictionary <string, object>
            {
                [payloadFieldName] = serviceFlags,
            };

            return(MiniJson.Serialize(payload));
        }
Пример #2
0
        static IServiceFlags ExtractServiceFlagsFromUnityWebRequest(UnityWebRequest unityWebRequest)
        {
            IDictionary <string, object> flags = null;

            if (UnityWebRequestHelper.IsUnityWebRequestReadyForTextExtract(unityWebRequest, out var jsonContent))
            {
                try
                {
                    var jsonEntries = (IDictionary <string, object>)MiniJson.Deserialize(jsonContent);
                    flags = (IDictionary <string, object>)jsonEntries[k_ServiceFlagsKey];
                }
                catch (Exception ex)
                {
                    Debug.LogError($"Exception occurred when fetching service flags:\n{ex.Message}");
                    flags = new Dictionary <string, object>();
                }
            }

            return(new ServiceFlags(flags));
        }