Ejemplo n.º 1
0
		/////////////////////////////////////////////////////////////////////////////

		public static string VisualizeList( NmpObjectList list, JSONDateFormat dateFormat = JSONDateFormat.ISODate )
		{
			var x = new JSONVisualizer( dateFormat );
			return x.List( list );
		}
Ejemplo n.º 2
0
		/////////////////////////////////////////////////////////////////////////////

		public static string VisualizeArray( NmpArray array, JSONDateFormat dateFormat = JSONDateFormat.ISODate )
		{
			var x = new JSONVisualizer( dateFormat );
			return x.Array( array );
		}
Ejemplo n.º 3
0
		/////////////////////////////////////////////////////////////////////////////

		static JSONValue()
		{
			DateFormat = JSONDateFormat.ISODate;
		}
Ejemplo n.º 4
0
		/////////////////////////////////////////////////////////////////////////////

		public JSONVisualizer( JSONDateFormat dateFormat = JSONDateFormat.ISODate )
		{
			JSONValue.DateFormat = dateFormat;
		}
Ejemplo n.º 5
0
		/////////////////////////////////////////////////////////////////////////////

		public static string Encode( object value, JSONDateFormat dateFormat = JSONDateFormat.ISODate )
		{
			// ******
			string valueStr = string.Empty;
			Type valueType = null == value ? null : value.GetType();
			TypeCode typeCode = Type.GetTypeCode( valueType );

			// ******
			if( TypeCode.Empty == typeCode ) {
				//
				// null
				//
				valueStr = "null";
			}
			else if( TypeCode.Boolean == typeCode ) {
				//
				// true or false
				//
				valueStr = ((bool) value) ? "true" : "false";
			}
			else if( typeCode >= TypeCode.SByte && typeCode <= TypeCode.Decimal ) {
				//
				// number, call ToString() - do NOT wrap with quotes
				//
				valueStr = value.ToString();
			}
			else if( TypeCode.DateTime == typeCode ) {
				//
				// date
				//
				long seconds = (long) ConvertToUnixTimestamp( (DateTime) value );

				if( JSONDateFormat.At1970 == dateFormat ) {
					valueStr = string.Format( "\"@{0}@\"", seconds );
				}
				else if( JSONDateFormat.Date1970 == dateFormat ) {
					valueStr = string.Format( "\"\\/Date({0})\\/\"", seconds );
				}
				else {	//if( JSONDateFormat.ISODate == dateFormat ) {
					//
					// ?? "s" or "u" ??
					//
					valueStr = string.Format( "\"{0}\"", ((DateTime) value).ToString("s") );
				}
			}
			else {
				//
				// string object and all other object types, call ToString()
				// and wrap the result in quotes - the result is a string
				//
				valueStr = string.Format( "\"{0}\"", value.ToString() );
			}

			// ******
			return valueStr;
		}