예제 #1
0
파일: JSON.cs 프로젝트: elrute/Triphulcas
		/// <summary>
		/// 
		/// </summary>
		public static void SerializeRPC(string id, object error, object obj, Stream stream) {
			JSONWriter writer = new JSONWriter(new StreamWriter(stream));

			// Start JSON output
			writer.WriteStartObject();
			writer.WritePropertyName("result");
			WriteValue(writer, obj);

			// Write id
			writer.WritePropertyName("id");
			writer.WriteValue(id);

			// Write error
			writer.WritePropertyName("error");
			writer.WriteValue(null);

			// Close
			writer.WriteEndObject();
			writer.Close();
		}
예제 #2
0
        /// <summary>
        ///
        /// </summary>
        public static void SerializeRPC(string id, object error, object obj, Stream stream)
        {
            JSONWriter writer = new JSONWriter(new StreamWriter(stream));

            // Start JSON output
            writer.WriteStartObject();
            writer.WritePropertyName("result");
            WriteValue(writer, obj);

            // Write id
            writer.WritePropertyName("id");
            writer.WriteValue(id);

            // Write error
            writer.WritePropertyName("error");
            writer.WriteValue(null);

            // Close
            writer.WriteEndObject();
            writer.Close();
        }
예제 #3
0
파일: JSON.cs 프로젝트: elrute/Triphulcas
		private static void WriteValue(JSONWriter writer, object obj) {
			if (obj == null)
				writer.WriteNull();

			if (obj is System.String)
				writer.WriteValue((string) obj);

			if (obj is System.Boolean)
				writer.WriteValue((bool) obj);

			if (obj is System.Double)
				writer.WriteValue(Convert.ToDouble(obj));

			if (obj is System.Int32)
				writer.WriteValue(Convert.ToInt32(obj));

			if (obj is System.Int64)
				writer.WriteValue(Convert.ToInt64(obj));

			if (obj is ArrayList) {
				writer.WriteStartArray();

				foreach (object val in ((ArrayList) obj))
					WriteValue(writer, val);

				writer.WriteEndArray();
			}

			if (obj is string[]) {
				writer.WriteStartArray();

				foreach (string val in ((string[]) obj))
					WriteValue(writer, val);

				writer.WriteEndArray();
			}

			if (obj is NameValueCollection) {
				writer.WriteStartObject();

				string[] keys = GetReversedKeys(obj);
				foreach (string key in keys) {
					writer.WritePropertyName(key);
					WriteValue(writer, ((NameValueCollection) obj)[key]);
				}

				writer.WriteEndObject();
			}

			if (obj is Hashtable) {
				writer.WriteStartObject();

				string[] keys = GetReversedKeys(obj);
				foreach (string key in keys) {
					writer.WritePropertyName((string) key);
					WriteValue(writer, ((Hashtable) obj)[key]);
				}

				writer.WriteEndObject();
			}
		}
예제 #4
0
        private static void WriteValue(JSONWriter writer, object obj)
        {
            if (obj == null)
            {
                writer.WriteNull();
            }

            if (obj is System.String)
            {
                writer.WriteValue((string)obj);
            }

            if (obj is System.Boolean)
            {
                writer.WriteValue((bool)obj);
            }

            if (obj is System.Double)
            {
                writer.WriteValue(Convert.ToDouble(obj));
            }

            if (obj is System.Int32)
            {
                writer.WriteValue(Convert.ToInt32(obj));
            }

            if (obj is System.Int64)
            {
                writer.WriteValue(Convert.ToInt64(obj));
            }

            if (obj is ArrayList)
            {
                writer.WriteStartArray();

                foreach (object val in ((ArrayList)obj))
                {
                    WriteValue(writer, val);
                }

                writer.WriteEndArray();
            }

            if (obj is string[])
            {
                writer.WriteStartArray();

                foreach (string val in ((string[])obj))
                {
                    WriteValue(writer, val);
                }

                writer.WriteEndArray();
            }

            if (obj is NameValueCollection)
            {
                writer.WriteStartObject();

                string[] keys = GetReversedKeys(obj);
                foreach (string key in keys)
                {
                    writer.WritePropertyName(key);
                    WriteValue(writer, ((NameValueCollection)obj)[key]);
                }

                writer.WriteEndObject();
            }

            if (obj is Hashtable)
            {
                writer.WriteStartObject();

                string[] keys = GetReversedKeys(obj);
                foreach (string key in keys)
                {
                    writer.WritePropertyName((string)key);
                    WriteValue(writer, ((Hashtable)obj)[key]);
                }

                writer.WriteEndObject();
            }
        }