Exemplo n.º 1
0
        private static void WriteJson(IJsonWrapper obj, JsonWriter writer)
        {
            if (obj == null)
            {
                writer.Write(null);
                return;
            }

            if (obj.IsString)
            {
                writer.Write(obj.GetString());
                return;
            }

            if (obj.IsBoolean)
            {
                writer.Write(obj.GetBoolean());
                return;
            }

            if (obj.IsDouble)
            {
                writer.Write(obj.GetDouble());
                return;
            }

            if (obj.IsInt)
            {
                writer.Write(obj.GetInt());
                return;
            }

            if (obj.IsUInt)
            {
                writer.Write(obj.GetUInt());
                return;
            }

            if (obj.IsLong)
            {
                writer.Write(obj.GetLong());
                return;
            }

            if (obj.IsULong)
            {
                writer.Write(obj.GetULong());
                return;
            }

            if (obj.IsArray)
            {
                writer.WriteArrayStart();
                foreach (object elem in (IList)obj)
                {
                    WriteJson((JsonData)elem, writer);
                }
                writer.WriteArrayEnd();

                return;
            }

            if (obj.IsObject)
            {
                writer.WriteObjectStart();

                foreach (DictionaryEntry entry in ((IDictionary)obj))
                {
                    writer.WritePropertyName((string)entry.Key);
                    WriteJson((JsonData)entry.Value, writer);
                }
                writer.WriteObjectEnd();

                return;
            }
        }
Exemplo n.º 2
0
 private static void WriteJson(IJsonWrapper obj, JsonWriter writer)
 {
     if (obj == null)
     {
         writer.Write(null);
     }
     else if (obj.IsString)
     {
         writer.Write(obj.GetString());
     }
     else if (obj.IsBoolean)
     {
         writer.Write(obj.GetBoolean());
     }
     else if (obj.IsDouble)
     {
         writer.Write(obj.GetDouble());
     }
     else if (obj.IsInt)
     {
         writer.Write(obj.GetInt());
     }
     else if (obj.IsUInt)
     {
         writer.Write(obj.GetUInt());
     }
     else if (obj.IsLong)
     {
         writer.Write(obj.GetLong());
     }
     else if (obj.IsULong)
     {
         writer.Write(obj.GetULong());
     }
     else if (obj.IsArray)
     {
         writer.WriteArrayStart();
         foreach (JsonData item in (IEnumerable)obj)
         {
             WriteJson(item, writer);
         }
         writer.WriteArrayEnd();
     }
     else if (obj.IsObject)
     {
         writer.WriteObjectStart();
         IDictionaryEnumerator enumerator2 = ((IDictionary)obj).GetEnumerator();
         try
         {
             while (enumerator2.MoveNext())
             {
                 DictionaryEntry dictionaryEntry = (DictionaryEntry)enumerator2.Current;
                 writer.WritePropertyName((string)dictionaryEntry.Key);
                 WriteJson((JsonData)dictionaryEntry.Value, writer);
             }
         }
         finally
         {
             (enumerator2 as IDisposable)?.Dispose();
         }
         writer.WriteObjectEnd();
     }
 }