コード例 #1
0
        public void Identify(String short_id, String long_id, Int32 heartbeat_interval, Boolean feature_negotiation)
        {
            dynamic json = new AgileObject();

            json.short_id            = short_id;
            json.long_id             = long_id;
            json.heartbeat_interval  = heartbeat_interval;
            json.feature_negotiation = feature_negotiation;

            var jsonText = JsonSerializer.Current.SerializeObject(json);

            SynchronizedWriteAction(() =>
            {
                _unsafe_writeAscii("IDENTIFY\n");
                _unsafe_writeBinary(PackMessage(jsonText));
            });
        }
コード例 #2
0
ファイル: JSONSerializer.cs プロジェクト: wcharczuk/NSQnet
        /// <summary>
        /// Converts the <see cref="T:Newtonsoft.Json.Linq.JToken" /> to <see cref="T:System.Object" /></summary>
        /// <param name="token">
        /// The token.
        /// </param>
        /// <returns>
        /// Returns the object.
        /// </returns>
        private static object ConvertJTokenToDictionary(JToken token)
        {
            if (token == null)
            {
                return(null);
            }

            //single value
            JValue jValue = token as JValue;

            if (jValue != null)
            {
                return(jValue.Value);
            }

            //an array of values
            JArray jContainer = token as JArray;

            if (jContainer != null)
            {
                JsonArray jsonList = new JsonArray();
                foreach (JToken arrayItem in (IEnumerable <JToken>)jContainer)
                {
                    jsonList.Add(ConvertJTokenToDictionary(arrayItem));
                }
                return(jsonList);
            }

            //a sub object
            AgileObject jsonObject = new AgileObject();
            IDictionary <string, object> jsonDict = jsonObject;

            (
                from childToken in token
                where childToken is JProperty
                select childToken as JProperty).ToList <JProperty>().ForEach(delegate(JProperty property)
            {
                jsonDict.Add(property.Name, ConvertJTokenToDictionary(property.Value));
            }
                                                                             );
            return(jsonObject);
        }