Beispiel #1
0
        private static void WriteJson(IJsonWrapper obj, JsonWriter writer)
        {
            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.IsLong)
            {
                writer.Write(obj.GetLong());
                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;
            }
        }
Beispiel #2
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.IsLong)
     {
         writer.Write(obj.GetLong());
         return;
     }
     if (obj.IsArray)
     {
         writer.WriteArrayStart();
         foreach (object current in obj)
         {
             JsonData.WriteJson((JsonData)current, writer);
         }
         writer.WriteArrayEnd();
         return;
     }
     if (obj.IsObject)
     {
         writer.WriteObjectStart();
         foreach (DictionaryEntry dictionaryEntry in obj)
         {
             writer.WritePropertyName((string)dictionaryEntry.Key);
             JsonData.WriteJson((JsonData)dictionaryEntry.Value, writer);
         }
         writer.WriteObjectEnd();
         return;
     }
 }
Beispiel #3
0
        private void CloneFromJsonWrapper(IJsonWrapper jsonWrapper)
        {
            JsonData jsonData = jsonWrapper as JsonData;

            if (jsonData != null)
            {
                type         = jsonData.type;
                json         = jsonData.json;
                inst_boolean = jsonData.inst_boolean;
                inst_double  = jsonData.inst_double;
                inst_int     = jsonData.inst_int;
                inst_long    = jsonData.inst_long;
                inst_string  = jsonData.inst_string;
                if (jsonData.inst_array != null)
                {
                    inst_array = new List <JsonData>(jsonData.inst_array);
                }
                if (jsonData.inst_object != null)
                {
                    inst_object = new Dictionary <string, JsonData>(jsonData.inst_object);
                }
                return;
            }
            type = jsonWrapper.GetJsonType();
            switch (type)
            {
            case JsonType.Boolean: inst_boolean = jsonWrapper.GetBoolean(); break;

            case JsonType.Int: inst_int = jsonWrapper.GetInt(); break;

            case JsonType.Long: inst_long = jsonWrapper.GetLong(); break;

            case JsonType.Double: inst_double = jsonWrapper.GetDouble(); break;

            case JsonType.String: inst_string = jsonWrapper.GetString(); break;

            case JsonType.Array:
                SetJsonType(JsonType.Array);
                foreach (object item in jsonWrapper as IList)
                {
                    Add(item as JsonData ?? new JsonData(item));
                }
                break;

            case JsonType.Object:
                SetJsonType(JsonType.Object);
                foreach (DictionaryEntry item in jsonWrapper as IDictionary)
                {
                    this[item.Key.ToString()] = item.Value as JsonData ?? new JsonData(item.Value);
                }
                break;
            }
        }
Beispiel #4
0
 private static void a(IJsonWrapper A_0, JsonWriter A_1)
 {
     if (A_0 == null)
     {
         A_1.Write(null);
         return;
     }
     if (A_0.IsString)
     {
         A_1.Write(A_0.GetString());
         return;
     }
     if (A_0.IsBoolean)
     {
         A_1.Write(A_0.GetBoolean());
         return;
     }
     if (A_0.IsDouble)
     {
         A_1.Write(A_0.GetDouble());
         return;
     }
     if (A_0.IsInt)
     {
         A_1.Write(A_0.GetInt());
         return;
     }
     if (A_0.IsLong)
     {
         A_1.Write(A_0.GetLong());
         return;
     }
     if (A_0.IsArray)
     {
         A_1.WriteArrayStart();
         foreach (object current in A_0)
         {
             JsonData.a((JsonData)current, A_1);
         }
         A_1.WriteArrayEnd();
         return;
     }
     if (A_0.IsObject)
     {
         A_1.WriteObjectStart();
         foreach (DictionaryEntry dictionaryEntry in A_0)
         {
             A_1.WritePropertyName((string)dictionaryEntry.Key);
             JsonData.a((JsonData)dictionaryEntry.Value, A_1);
         }
         A_1.WriteObjectEnd();
     }
 }
Beispiel #5
0
 private static void WriteJson(IJsonWrapper obj, JsonWriter writer)
 {
     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.IsArray)
     {
         writer.WriteArrayStart();
         foreach (object current in (IList)obj)
         {
             JsonData.WriteJson((JsonData)current, writer);
         }
         writer.WriteArrayEnd();
     }
     else if (obj.IsObject)
     {
         writer.WriteObjectStart();
         foreach (DictionaryEntry dictionaryEntry in (IDictionary)obj)
         {
             writer.WritePropertyName((string)dictionaryEntry.Key);
             JsonData.WriteJson((JsonData)dictionaryEntry.Value, writer);
         }
         writer.WriteObjectEnd();
     }
     else if (obj.GetJsonType() == JsonType.None)
     {
         //为空的情况下,也要能写一对花括号,避免格式出错。
         writer.WriteObjectStart();
         writer.WriteObjectEnd();
     }
 }
Beispiel #6
0
        public static double GetJsonDouble(this JsonData data)
        {
            IJsonWrapper id = data;

            if (id.IsInt)
            {
                return(id.GetInt());
            }
            else if (id.IsLong)
            {
                return(id.GetLong());
            }
            return(id.GetDouble());
        }
Beispiel #7
0
 private static void WriteJson(IJsonWrapper obj, JsonWriter writer, bool toHex = true)
 {
     if (obj == null)
     {
         writer.Write((string)null, true);
     }
     else if (obj.IsString)
     {
         writer.Write(obj.GetString(), toHex);
     }
     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.IsLong)
     {
         writer.Write(obj.GetLong());
     }
     else if (obj.IsArray)
     {
         writer.WriteArrayStart();
         foreach (IJsonWrapper jsonWrapper in (IEnumerable)obj)
         {
             JsonData.WriteJson(jsonWrapper, writer, toHex);
         }
         writer.WriteArrayEnd();
     }
     else
     {
         if (!obj.IsObject)
         {
             return;
         }
         writer.WriteObjectStart();
         foreach (DictionaryEntry dictionaryEntry in (IDictionary)obj)
         {
             writer.WritePropertyName((string)dictionaryEntry.Key);
             JsonData.WriteJson((IJsonWrapper)dictionaryEntry.Value, writer, toHex);
         }
         writer.WriteObjectEnd();
     }
 }
Beispiel #8
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.IsLong)
     {
         writer.Write(obj.GetLong());
     }
     else if (obj.IsArray)
     {
         writer.WriteArrayStart();
         foreach (object item in (IEnumerable)obj)
         {
             WriteJson((JsonData)item, writer);
         }
         writer.WriteArrayEnd();
     }
     else
     {
         if (!obj.IsObject)
         {
             return;
         }
         writer.WriteObjectStart();
         foreach (DictionaryEntry item2 in (IDictionary)obj)
         {
             writer.WritePropertyName((string)item2.Key);
             WriteJson((JsonData)item2.Value, writer);
         }
         writer.WriteObjectEnd();
     }
 }
Beispiel #9
0
        public static string AsString(this IJsonWrapper source, string defaultValue = "")
        {
            if (source == null)
            {
                return(defaultValue);
            }
            switch (source.GetJsonType())
            {
            case JsonType.String: return(source.GetString());

            case JsonType.Double: return(source.GetDouble().ToString());

            case JsonType.Int: return(source.GetInt().ToString());

            case JsonType.Long: return(source.GetLong().ToString());

            case JsonType.Boolean: return(source.GetBoolean().ToString());

            case JsonType.Array:
            case JsonType.Object: return(source.Count.ToString());
            }
            return(defaultValue);
        }
Beispiel #10
0
        private static Document MapFromJsonObject(IJsonWrapper jsonWrapper)
        {
            if (null == jsonWrapper)
            {
                return(new Document());
            }

            switch (jsonWrapper.GetJsonType())
            {
            case JsonType.None:
                return(new Document());

            case JsonType.Boolean:
                return(new Document(jsonWrapper.GetBoolean()));

            case JsonType.Double:
                return(new Document(jsonWrapper.GetDouble()));

            case JsonType.Int:
                return(new Document(jsonWrapper.GetInt()));

            case JsonType.Long:
                return(new Document(jsonWrapper.GetLong()));

            case JsonType.String:
                return(new Document(jsonWrapper.GetString()));

            case JsonType.Array:
                return(new Document((jsonWrapper as IList).Cast <IJsonWrapper>().Select(MapFromJsonObject).ToList()));

            case JsonType.Object:
                return(new Document(MapDictionary(jsonWrapper)));

            default:
                throw new ArgumentException($"Unknown JSON type: {jsonWrapper.GetJsonType()}");
            }
        }
Beispiel #11
0
        private static void WriteJson(IJsonWrapper wrapper, JsonWriter writer)
        {
            if (wrapper == null && !JsonWriter.SkipNullMember)
            {
                writer.Write(null);
                return;
            }

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

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

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

            if (wrapper.IsInt)
            {
                writer.Write(wrapper.GetInt());
                return;
            }
            if (wrapper.IsFloat)
            {
                writer.Write(wrapper.GetFloat());
                return;
            }
            if (wrapper.IsLong)
            {
                writer.Write(wrapper.GetLong());
                return;
            }

            if (wrapper.IsArray)
            {
                writer.WriteArrayStart();
                foreach (var elem in (IList)wrapper)
                {
                    WriteJson((JsonData)elem, writer);
                }
                writer.WriteArrayEnd();
                return;
            }

            if (wrapper.IsObject)
            {
                if (JsonWriter.SkipNullMember && wrapper.Count <= 0)
                {
                    return;
                }

                writer.WriteObjectStart();

                foreach (DictionaryEntry entry in (IDictionary)wrapper)
                {
                    if (JsonWriter.SkipNullMember)
                    {
                        var type = ((JsonData)entry.Value).GetJsonType();
                        if (type == JsonType.None)
                        {
                            continue;
                        }
                        if (type == JsonType.Array && ((IList)entry.Value).Count <= 0)
                        {
                            continue;
                        }
                    }
                    writer.WritePropertyName((string)entry.Key);
                    WriteJson((JsonData)entry.Value, writer);
                }
                writer.WriteObjectEnd();

                return;
            }

            if (wrapper.GetJsonType() == JsonType.None)
            {
                writer.WriteObjectStart();
                writer.WriteObjectEnd();
            }
        }
        private static void WriteJson(IJsonWrapper obj, JsonWriter writer)
        {
            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.IsLong) {
                writer.Write (obj.GetLong ());
                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;
            }
        }
Beispiel #13
0
 private static void WriteJson(IJsonWrapper obj, JsonWriter writer)
 {
     if (obj == null)
     {
         writer.Write((string)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.IsLong)
     {
         writer.Write(obj.GetLong());
     }
     else if (obj.IsArray)
     {
         writer.WriteArrayStart();
         IEnumerator enumerator = obj.GetEnumerator();
         try
         {
             while (enumerator.MoveNext())
             {
                 object current = enumerator.Current;
                 WriteJson((JsonData)current, writer);
             }
         }
         finally
         {
             IDisposable disposable = enumerator as IDisposable;
             if (disposable == null)
             {
             }
             disposable.Dispose();
         }
         writer.WriteArrayEnd();
     }
     else if (obj.IsObject)
     {
         writer.WriteObjectStart();
         IDictionaryEnumerator enumerator2 = obj.GetEnumerator();
         try
         {
             while (enumerator2.MoveNext())
             {
                 DictionaryEntry entry = (DictionaryEntry)enumerator2.Current;
                 writer.WritePropertyName((string)entry.Key);
                 WriteJson((JsonData)entry.Value, writer);
             }
         }
         finally
         {
             IDisposable disposable2 = enumerator2 as IDisposable;
             if (disposable2 == null)
             {
             }
             disposable2.Dispose();
         }
         writer.WriteObjectEnd();
     }
 }
Beispiel #14
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();
     }
 }
Beispiel #15
0
        private static void WriteJson(IJsonWrapper obj, JsonWriter writer)
        {
            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.IsLong)
            {
                writer.Write(obj.GetLong());
                return;
            }

            if (obj.IsArray)
            {
                writer.WriteArrayStart();
                {
                    // foreach(var elem in (IList) obj)
                    var __enumerator3 = ((IList)obj).GetEnumerator();
                    while (__enumerator3.MoveNext())
                    {
                        var elem = (object)__enumerator3.Current;
                        WriteJson((JsonData)elem, writer);
                    }
                }
                writer.WriteArrayEnd();

                return;
            }

            if (obj.IsObject)
            {
                writer.WriteObjectStart();
                {
                    // foreach(var entry in ((IDictionary) obj))
                    var __enumerator4 = (((IDictionary)obj)).GetEnumerator();
                    while (__enumerator4.MoveNext())
                    {
                        var entry = (DictionaryEntry)__enumerator4.Current;
                        {
                            writer.WritePropertyName((string)entry.Key);
                            WriteJson((JsonData)entry.Value, writer);
                        }
                    }
                }
                writer.WriteObjectEnd();

                return;
            }
        }
Beispiel #16
0
        private static void WriteJson(IJsonWrapper obj, JsonWriter writer, bool indent = true)
        {
            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.IsLong)
            {
                writer.Write(obj.GetLong());
                return;
            }

            if (obj.IsArray)
            {
                bool isPretty = writer.PrettyPrint;
                writer.PrettyPrint = true;
                writer.WriteArrayStart(indent);
                writer.PrettyPrint = false;
                foreach (object elem in (IList)obj)
                {
                    WriteJson((JsonData)elem, writer, false);
                }

                writer.PrettyPrint = isPretty;
                writer.WriteArrayEnd(indent);

                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;
            }
        }
Beispiel #17
0
 // Token: 0x060156C5 RID: 87749 RVA: 0x0056E690 File Offset: 0x0056C890
 private static void WriteJson(IJsonWrapper obj, JsonWriter writer)
 {
     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.IsLong)
     {
         writer.Write(obj.GetLong());
         return;
     }
     if (obj.IsArray)
     {
         writer.WriteArrayStart();
         IEnumerator enumerator = obj.GetEnumerator();
         try
         {
             while (enumerator.MoveNext())
             {
                 object obj2 = enumerator.Current;
                 JsonData.WriteJson((JsonData)obj2, writer);
             }
         }
         finally
         {
             IDisposable disposable;
             if ((disposable = (enumerator as IDisposable)) != null)
             {
                 disposable.Dispose();
             }
         }
         writer.WriteArrayEnd();
         return;
     }
     if (obj.IsObject)
     {
         writer.WriteObjectStart();
         IDictionaryEnumerator enumerator2 = obj.GetEnumerator();
         try
         {
             while (enumerator2.MoveNext())
             {
                 object          obj3            = enumerator2.Current;
                 DictionaryEntry dictionaryEntry = (DictionaryEntry)obj3;
                 writer.WritePropertyName((string)dictionaryEntry.Key);
                 JsonData.WriteJson((JsonData)dictionaryEntry.Value, writer);
             }
         }
         finally
         {
             IDisposable disposable2;
             if ((disposable2 = (enumerator2 as IDisposable)) != null)
             {
                 disposable2.Dispose();
             }
         }
         writer.WriteObjectEnd();
         return;
     }
 }
Beispiel #18
0
        private static void WriteJson(IJsonWrapper wrapper, JsonWriter writer)
        {
            if (wrapper == null)
            {
                writer.Write(null);
                return;
            }

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

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

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

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

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

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

            if (wrapper.IsObject)
            {
                if (((IDictionary)wrapper).Count <= 0)
                {
                    return;
                }

                writer.WriteObjectStart();

                foreach (DictionaryEntry entry in ((IDictionary)wrapper))
                {
                    //TODO: ignore null entry
                    var data = (JsonData)entry.Value;
                    var type = data.GetJsonType();
                    if (type == JsonType.None)
                    {
                        continue;
                    }
                    if (type == JsonType.Array && ((IList)entry.Value).Count <= 0)
                    {
                        continue;
                    }
                    writer.WritePropertyName((string)entry.Key);
                    WriteJson(data, writer);
                }
                writer.WriteObjectEnd();

                return;
            }

            if (wrapper.GetJsonType() == JsonType.None)
            {
                writer.WriteObjectStart();
                writer.WriteObjectEnd();
                return;
            }
        }