How to use Clear method of SimpleJSON.LinqEnumerator class

Best Vstest code snippet using SimpleJSON.LinqEnumerator.Clear

SimpleJSON.cs

Source:SimpleJSON.cs Github

copy

Full Screen

...188 public virtual JSONNode Remove(JSONNode aNode)189 {190 return aNode;191 }192 public virtual void Clear() { }193 public virtual JSONNode Clone()194 {195 return null;196 }197 public virtual IEnumerable<JSONNode> Children198 {199 get200 {201 yield break;202 }203 }204 public IEnumerable<JSONNode> DeepChildren205 {206 get207 {208 foreach (var C in Children)209 foreach (var D in C.DeepChildren)210 yield return D;211 }212 }213 public virtual bool HasKey(string aKey)214 {215 return false;216 }217 public virtual JSONNode GetValueOrDefault(string aKey, JSONNode aDefault)218 {219 return aDefault;220 }221 public override string ToString()222 {223 StringBuilder sb = new StringBuilder();224 WriteToStringBuilder(sb, 0, 0, JSONTextMode.Compact);225 return sb.ToString();226 }227 public virtual string ToString(int aIndent)228 {229 StringBuilder sb = new StringBuilder();230 WriteToStringBuilder(sb, 0, aIndent, JSONTextMode.Indent);231 return sb.ToString();232 }233 internal abstract void WriteToStringBuilder(StringBuilder aSB, int aIndent, int aIndentInc, JSONTextMode aMode);234 public abstract Enumerator GetEnumerator();235 public IEnumerable<KeyValuePair<string, JSONNode>> Linq { get { return new LinqEnumerator(this); } }236 public KeyEnumerator Keys { get { return new KeyEnumerator(GetEnumerator()); } }237 public ValueEnumerator Values { get { return new ValueEnumerator(GetEnumerator()); } }238 #endregion common interface239 #region typecasting properties240 public virtual double AsDouble241 {242 get243 {244 double v = 0.0;245 if (double.TryParse(Value, NumberStyles.Float, CultureInfo.InvariantCulture, out v))246 return v;247 return 0.0;248 }249 set250 {251 Value = value.ToString(CultureInfo.InvariantCulture);252 }253 }254 public virtual int AsInt255 {256 get { return (int)AsDouble; }257 set { AsDouble = value; }258 }259 public virtual float AsFloat260 {261 get { return (float)AsDouble; }262 set { AsDouble = value; }263 }264 public virtual bool AsBool265 {266 get267 {268 bool v = false;269 if (bool.TryParse(Value, out v))270 return v;271 return !string.IsNullOrEmpty(Value);272 }273 set274 {275 Value = (value) ? "true" : "false";276 }277 }278 public virtual long AsLong279 {280 get281 {282 long val = 0;283 if (long.TryParse(Value, out val))284 return val;285 return 0L;286 }287 set288 {289 Value = value.ToString();290 }291 }292 public virtual ulong AsULong293 {294 get295 {296 ulong val = 0;297 if (ulong.TryParse(Value, out val))298 return val;299 return 0;300 }301 set302 {303 Value = value.ToString();304 }305 }306 public virtual JSONArray AsArray307 {308 get309 {310 return this as JSONArray;311 }312 }313 public virtual JSONObject AsObject314 {315 get316 {317 return this as JSONObject;318 }319 }320 #endregion typecasting properties321 #region operators322 public static implicit operator JSONNode(string s)323 {324 return (s == null) ? (JSONNode) JSONNull.CreateOrGet() : new JSONString(s);325 }326 public static implicit operator string(JSONNode d)327 {328 return (d == null) ? null : d.Value;329 }330 public static implicit operator JSONNode(double n)331 {332 return new JSONNumber(n);333 }334 public static implicit operator double(JSONNode d)335 {336 return (d == null) ? 0 : d.AsDouble;337 }338 public static implicit operator JSONNode(float n)339 {340 return new JSONNumber(n);341 }342 public static implicit operator float(JSONNode d)343 {344 return (d == null) ? 0 : d.AsFloat;345 }346 public static implicit operator JSONNode(int n)347 {348 return new JSONNumber(n);349 }350 public static implicit operator int(JSONNode d)351 {352 return (d == null) ? 0 : d.AsInt;353 }354 public static implicit operator JSONNode(long n)355 {356 if (longAsString)357 return new JSONString(n.ToString());358 return new JSONNumber(n);359 }360 public static implicit operator long(JSONNode d)361 {362 return (d == null) ? 0L : d.AsLong;363 }364 public static implicit operator JSONNode(ulong n)365 {366 if (longAsString)367 return new JSONString(n.ToString());368 return new JSONNumber(n);369 }370 public static implicit operator ulong(JSONNode d)371 {372 return (d == null) ? 0 : d.AsULong;373 }374 public static implicit operator JSONNode(bool b)375 {376 return new JSONBool(b);377 }378 public static implicit operator bool(JSONNode d)379 {380 return (d == null) ? false : d.AsBool;381 }382 public static implicit operator JSONNode(KeyValuePair<string, JSONNode> aKeyValue)383 {384 return aKeyValue.Value;385 }386 public static bool operator ==(JSONNode a, object b)387 {388 if (ReferenceEquals(a, b))389 return true;390 bool aIsNull = a is JSONNull || ReferenceEquals(a, null) || a is JSONLazyCreator;391 bool bIsNull = b is JSONNull || ReferenceEquals(b, null) || b is JSONLazyCreator;392 if (aIsNull && bIsNull)393 return true;394 return !aIsNull && a.Equals(b);395 }396 public static bool operator !=(JSONNode a, object b)397 {398 return !(a == b);399 }400 public override bool Equals(object obj)401 {402 return ReferenceEquals(this, obj);403 }404 public override int GetHashCode()405 {406 return base.GetHashCode();407 }408 #endregion operators409 [ThreadStatic]410 private static StringBuilder m_EscapeBuilder;411 internal static StringBuilder EscapeBuilder412 {413 get414 {415 if (m_EscapeBuilder == null)416 m_EscapeBuilder = new StringBuilder();417 return m_EscapeBuilder;418 }419 }420 internal static string Escape(string aText)421 {422 var sb = EscapeBuilder;423 sb.Length = 0;424 if (sb.Capacity < aText.Length + aText.Length / 10)425 sb.Capacity = aText.Length + aText.Length / 10;426 foreach (char c in aText)427 {428 switch (c)429 {430 case '\\':431 sb.Append("\\\\");432 break;433 case '\"':434 sb.Append("\\\"");435 break;436 case '\n':437 sb.Append("\\n");438 break;439 case '\r':440 sb.Append("\\r");441 break;442 case '\t':443 sb.Append("\\t");444 break;445 case '\b':446 sb.Append("\\b");447 break;448 case '\f':449 sb.Append("\\f");450 break;451 default:452 if (c < ' ' || (forceASCII && c > 127))453 {454 ushort val = c;455 sb.Append("\\u").Append(val.ToString("X4"));456 }457 else458 sb.Append(c);459 break;460 }461 }462 string result = sb.ToString();463 sb.Length = 0;464 return result;465 }466 private static JSONNode ParseElement(string token, bool quoted)467 {468 if (quoted)469 return token;470 if (token.Length <= 5)471 {472 string tmp = token.ToLower();473 if (tmp == "false" || tmp == "true")474 return tmp == "true";475 if (tmp == "null")476 return JSONNull.CreateOrGet();477 }478 double val;479 if (double.TryParse(token, NumberStyles.Float, CultureInfo.InvariantCulture, out val))480 return val;481 else482 return token;483 }484 public static JSONNode Parse(string aJSON)485 {486 Stack<JSONNode> stack = new Stack<JSONNode>();487 JSONNode ctx = null;488 int i = 0;489 StringBuilder Token = new StringBuilder();490 string TokenName = "";491 bool QuoteMode = false;492 bool TokenIsQuoted = false;493 bool HasNewlineChar = false;494 while (i < aJSON.Length)495 {496 switch (aJSON[i])497 {498 case '{':499 if (QuoteMode)500 {501 Token.Append(aJSON[i]);502 break;503 }504 stack.Push(new JSONObject());505 if (ctx != null)506 {507 ctx.Add(TokenName, stack.Peek());508 }509 TokenName = "";510 Token.Length = 0;511 ctx = stack.Peek();512 HasNewlineChar = false;513 break;514 case '[':515 if (QuoteMode)516 {517 Token.Append(aJSON[i]);518 break;519 }520 stack.Push(new JSONArray());521 if (ctx != null)522 {523 ctx.Add(TokenName, stack.Peek());524 }525 TokenName = "";526 Token.Length = 0;527 ctx = stack.Peek();528 HasNewlineChar = false;529 break;530 case '}':531 case ']':532 if (QuoteMode)533 {534 Token.Append(aJSON[i]);535 break;536 }537 if (stack.Count == 0)538 throw new Exception("JSON Parse: Too many closing brackets");539 stack.Pop();540 if (Token.Length > 0 || TokenIsQuoted)541 ctx.Add(TokenName, ParseElement(Token.ToString(), TokenIsQuoted));542 if (ctx != null)543 ctx.Inline = !HasNewlineChar;544 TokenIsQuoted = false;545 TokenName = "";546 Token.Length = 0;547 if (stack.Count > 0)548 ctx = stack.Peek();549 break;550 case ':':551 if (QuoteMode)552 {553 Token.Append(aJSON[i]);554 break;555 }556 TokenName = Token.ToString();557 Token.Length = 0;558 TokenIsQuoted = false;559 break;560 case '"':561 QuoteMode ^= true;562 TokenIsQuoted |= QuoteMode;563 break;564 case ',':565 if (QuoteMode)566 {567 Token.Append(aJSON[i]);568 break;569 }570 if (Token.Length > 0 || TokenIsQuoted)571 ctx.Add(TokenName, ParseElement(Token.ToString(), TokenIsQuoted));572 TokenIsQuoted = false;573 TokenName = "";574 Token.Length = 0;575 TokenIsQuoted = false;576 break;577 case '\r':578 case '\n':579 HasNewlineChar = true;580 break;581 case ' ':582 case '\t':583 if (QuoteMode)584 Token.Append(aJSON[i]);585 break;586 case '\\':587 ++i;588 if (QuoteMode)589 {590 char C = aJSON[i];591 switch (C)592 {593 case 't':594 Token.Append('\t');595 break;596 case 'r':597 Token.Append('\r');598 break;599 case 'n':600 Token.Append('\n');601 break;602 case 'b':603 Token.Append('\b');604 break;605 case 'f':606 Token.Append('\f');607 break;608 case 'u':609 {610 string s = aJSON.Substring(i + 1, 4);611 Token.Append((char)int.Parse(612 s,613 System.Globalization.NumberStyles.AllowHexSpecifier));614 i += 4;615 break;616 }617 default:618 Token.Append(C);619 break;620 }621 }622 break;623 case '/':624 if (allowLineComments && !QuoteMode && i + 1 < aJSON.Length && aJSON[i + 1] == '/')625 {626 while (++i < aJSON.Length && aJSON[i] != '\n' && aJSON[i] != '\r') ;627 break;628 }629 Token.Append(aJSON[i]);630 break;631 case '\uFEFF': // remove / ignore BOM (Byte Order Mark)632 break;633 default:634 Token.Append(aJSON[i]);635 break;636 }637 ++i;638 }639 if (QuoteMode)640 {641 throw new Exception("JSON Parse: Quotation marks seems to be messed up.");642 }643 if (ctx == null)644 return ParseElement(Token.ToString(), TokenIsQuoted);645 return ctx;646 }647 public virtual void Serialize(System.IO.BinaryWriter aWriter)648 {649 }650 public void SaveToStream(System.IO.Stream aData)651 {652 var W = new System.IO.BinaryWriter(aData);653 Serialize(W);654 }655#if USE_SharpZipLib656 public void SaveToCompressedStream(System.IO.Stream aData)657 {658 using (var gzipOut = new ICSharpCode.SharpZipLib.BZip2.BZip2OutputStream(aData))659 {660 gzipOut.IsStreamOwner = false;661 SaveToStream(gzipOut);662 gzipOut.Close();663 }664 }665 public void SaveToCompressedFile(string aFileName)666 {667#if USE_FileIO668 System.IO.Directory.CreateDirectory((new System.IO.FileInfo(aFileName)).Directory.FullName);669 using(var F = System.IO.File.OpenWrite(aFileName))670 {671 SaveToCompressedStream(F);672 }673#else674 throw new Exception("Can't use File IO stuff in the webplayer");675#endif676 }677 public string SaveToCompressedBase64()678 {679 using (var stream = new System.IO.MemoryStream())680 {681 SaveToCompressedStream(stream);682 stream.Position = 0;683 return System.Convert.ToBase64String(stream.ToArray());684 }685 }686#else687 public void SaveToCompressedStream(System.IO.Stream aData)688 {689 throw new Exception("Can't use compressed functions. You need include the SharpZipLib and uncomment the define at the top of SimpleJSON");690 }691 public void SaveToCompressedFile(string aFileName)692 {693 throw new Exception("Can't use compressed functions. You need include the SharpZipLib and uncomment the define at the top of SimpleJSON");694 }695 public string SaveToCompressedBase64()696 {697 throw new Exception("Can't use compressed functions. You need include the SharpZipLib and uncomment the define at the top of SimpleJSON");698 }699#endif700 public void SaveToFile(string aFileName)701 {702#if USE_FileIO703 System.IO.Directory.CreateDirectory((new System.IO.FileInfo(aFileName)).Directory.FullName);704 using (var F = System.IO.File.OpenWrite(aFileName))705 {706 SaveToStream(F);707 }708#else709 throw new Exception ("Can't use File IO stuff in the webplayer");710#endif711 }712 public string SaveToBase64()713 {714 using (var stream = new System.IO.MemoryStream())715 {716 SaveToStream(stream);717 stream.Position = 0;718 return System.Convert.ToBase64String(stream.ToArray());719 }720 }721 public static JSONNode Deserialize(System.IO.BinaryReader aReader)722 {723 JSONNodeType type = (JSONNodeType)aReader.ReadByte();724 switch (type)725 {726 case JSONNodeType.Array:727 {728 int count = aReader.ReadInt32();729 JSONArray tmp = new JSONArray();730 for (int i = 0; i < count; i++)731 tmp.Add(Deserialize(aReader));732 return tmp;733 }734 case JSONNodeType.Object:735 {736 int count = aReader.ReadInt32();737 JSONObject tmp = new JSONObject();738 for (int i = 0; i < count; i++)739 {740 string key = aReader.ReadString();741 var val = Deserialize(aReader);742 tmp.Add(key, val);743 }744 return tmp;745 }746 case JSONNodeType.String:747 {748 return new JSONString(aReader.ReadString());749 }750 case JSONNodeType.Number:751 {752 return new JSONNumber(aReader.ReadDouble());753 }754 case JSONNodeType.Boolean:755 {756 return new JSONBool(aReader.ReadBoolean());757 }758 case JSONNodeType.NullValue:759 {760 return new JSONNull();761 }762 default:763 {764 throw new Exception("Error deserializing JSON. Unknown tag: " + type);765 }766 }767 }768#if USE_SharpZipLib769 public static JSONNode LoadFromCompressedStream(System.IO.Stream aData)770 {771 var zin = new ICSharpCode.SharpZipLib.BZip2.BZip2InputStream(aData);772 return LoadFromStream(zin);773 }774 public static JSONNode LoadFromCompressedFile(string aFileName)775 {776#if USE_FileIO777 using(var F = System.IO.File.OpenRead(aFileName))778 {779 return LoadFromCompressedStream(F);780 }781#else782 throw new Exception("Can't use File IO stuff in the webplayer");783#endif784 }785 public static JSONNode LoadFromCompressedBase64(string aBase64)786 {787 var tmp = System.Convert.FromBase64String(aBase64);788 var stream = new System.IO.MemoryStream(tmp);789 stream.Position = 0;790 return LoadFromCompressedStream(stream);791 }792#else793 public static JSONNode LoadFromCompressedFile(string aFileName)794 {795 throw new Exception("Can't use compressed functions. You need include the SharpZipLib and uncomment the define at the top of SimpleJSON");796 }797 public static JSONNode LoadFromCompressedStream(System.IO.Stream aData)798 {799 throw new Exception("Can't use compressed functions. You need include the SharpZipLib and uncomment the define at the top of SimpleJSON");800 }801 public static JSONNode LoadFromCompressedBase64(string aBase64)802 {803 throw new Exception("Can't use compressed functions. You need include the SharpZipLib and uncomment the define at the top of SimpleJSON");804 }805#endif806 public static JSONNode LoadFromStream(System.IO.Stream aData)807 {808 using (var R = new System.IO.BinaryReader(aData))809 {810 return Deserialize(R);811 }812 }813 public static JSONNode LoadFromFile(string aFileName)814 {815#if USE_FileIO816 using (var F = System.IO.File.OpenRead(aFileName))817 {818 return LoadFromStream(F);819 }820#else821 throw new Exception ("Can't use File IO stuff in the webplayer");822#endif823 }824 public static JSONNode LoadFromBase64(string aBase64)825 {826 var tmp = System.Convert.FromBase64String(aBase64);827 var stream = new System.IO.MemoryStream(tmp);828 stream.Position = 0;829 return LoadFromStream(stream);830 }831 static string SPLIT_RE = @",(?=(?:[^""]*""[^""]*"")*(?![^""]*""))";832 static string LINE_SPLIT_RE = @"\r\n|\n\r|\n|\r";833 static char[] TRIM_CHARS = { '\"' };834 public static JSONNode ParseCSV(string csvString)835 {836 JSONNode output = new JSONArray();837 var lines = Regex.Split(csvString, LINE_SPLIT_RE);838 if (lines.Length <= 1)839 {840 return null;841 }842 var header = Regex.Split(lines[0], SPLIT_RE);843 for (var i = 1; i < lines.Length; i++)844 {845 JSONObject obj = new JSONObject();846 var values = Regex.Split(lines[i], SPLIT_RE);847 if (values.Length == 0 || values[0] == "") continue;848 for (var j = 0; j < header.Length && j < values.Length; j++)849 {850 string value = values[j];851 value = value.TrimStart(TRIM_CHARS).TrimEnd(TRIM_CHARS).Replace("\\", "");852 float floatValue = 0.0f;853 if(float.TryParse(value, out floatValue)) {854 obj.Add(header[j], new JSONNumber(floatValue));855 } else {856 obj.Add(header[j], new JSONString(value));857 }858 }859 output.Add(obj);860 }861 return output;862 }863 }864 // End of JSONNode865 public partial class JSONArray : JSONNode866 {867 private List<JSONNode> m_List = new List<JSONNode>();868 private bool inline = false;869 public override bool Inline870 {871 get { return inline; }872 set { inline = value; }873 }874 public override JSONNodeType Tag { get { return JSONNodeType.Array; } }875 public override bool IsArray { get { return true; } }876 public override Enumerator GetEnumerator() { return new Enumerator(m_List.GetEnumerator()); }877 public override JSONNode this[int aIndex]878 {879 get880 {881 if (aIndex < 0 || aIndex >= m_List.Count)882 return new JSONLazyCreator(this);883 return m_List[aIndex];884 }885 set886 {887 if (value == null)888 value = JSONNull.CreateOrGet();889 if (aIndex < 0 || aIndex >= m_List.Count)890 m_List.Add(value);891 else892 m_List[aIndex] = value;893 }894 }895 public override JSONNode this[string aKey]896 {897 get { return new JSONLazyCreator(this); }898 set899 {900 if (value == null)901 value = JSONNull.CreateOrGet();902 m_List.Add(value);903 }904 }905 public override int Count906 {907 get { return m_List.Count; }908 }909 public override void Add(string aKey, JSONNode aItem)910 {911 if (aItem == null)912 aItem = JSONNull.CreateOrGet();913 m_List.Add(aItem);914 }915 public override JSONNode Remove(int aIndex)916 {917 if (aIndex < 0 || aIndex >= m_List.Count)918 return null;919 JSONNode tmp = m_List[aIndex];920 m_List.RemoveAt(aIndex);921 return tmp;922 }923 public override JSONNode Remove(JSONNode aNode)924 {925 m_List.Remove(aNode);926 return aNode;927 }928 public override void Clear()929 {930 m_List.Clear();931 }932 public override JSONNode Clone()933 {934 var node = new JSONArray();935 node.m_List.Capacity = m_List.Capacity;936 foreach(var n in m_List)937 {938 if (n != null)939 node.Add(n.Clone());940 else941 node.Add(null);942 }943 return node;944 }945 public override IEnumerable<JSONNode> Children946 {947 get948 {949 foreach (JSONNode N in m_List)950 yield return N;951 }952 }953 internal override void WriteToStringBuilder(StringBuilder aSB, int aIndent, int aIndentInc, JSONTextMode aMode)954 {955 aSB.Append('[');956 int count = m_List.Count;957 if (inline)958 aMode = JSONTextMode.Compact;959 for (int i = 0; i < count; i++)960 {961 if (i > 0)962 aSB.Append(',');963 if (aMode == JSONTextMode.Indent)964 aSB.AppendLine();965 if (aMode == JSONTextMode.Indent)966 aSB.Append(' ', aIndent + aIndentInc);967 m_List[i].WriteToStringBuilder(aSB, aIndent + aIndentInc, aIndentInc, aMode);968 }969 if (aMode == JSONTextMode.Indent)970 aSB.AppendLine().Append(' ', aIndent);971 aSB.Append(']');972 }973 }974 // End of JSONArray975 public partial class JSONObject : JSONNode976 {977 private Dictionary<string, JSONNode> m_Dict = new Dictionary<string, JSONNode>();978 private bool inline = false;979 public override bool Inline980 {981 get { return inline; }982 set { inline = value; }983 }984 public override JSONNodeType Tag { get { return JSONNodeType.Object; } }985 public override bool IsObject { get { return true; } }986 public override Enumerator GetEnumerator() { return new Enumerator(m_Dict.GetEnumerator()); }987 public override JSONNode this[string aKey]988 {989 get990 {991 if (m_Dict.ContainsKey(aKey))992 return m_Dict[aKey];993 else994 return new JSONLazyCreator(this, aKey);995 }996 set997 {998 if (value == null)999 value = JSONNull.CreateOrGet();1000 if (m_Dict.ContainsKey(aKey))1001 m_Dict[aKey] = value;1002 else1003 m_Dict.Add(aKey, value);1004 }1005 }1006 public override JSONNode this[int aIndex]1007 {1008 get1009 {1010 if (aIndex < 0 || aIndex >= m_Dict.Count)1011 return null;1012 return m_Dict.ElementAt(aIndex).Value;1013 }1014 set1015 {1016 if (value == null)1017 value = JSONNull.CreateOrGet();1018 if (aIndex < 0 || aIndex >= m_Dict.Count)1019 return;1020 string key = m_Dict.ElementAt(aIndex).Key;1021 m_Dict[key] = value;1022 }1023 }1024 public override int Count1025 {1026 get { return m_Dict.Count; }1027 }1028 public override void Add(string aKey, JSONNode aItem)1029 {1030 if (aItem == null)1031 aItem = JSONNull.CreateOrGet();1032 if (aKey != null)1033 {1034 if (m_Dict.ContainsKey(aKey))1035 m_Dict[aKey] = aItem;1036 else1037 m_Dict.Add(aKey, aItem);1038 }1039 else1040 m_Dict.Add(Guid.NewGuid().ToString(), aItem);1041 }1042 public override JSONNode Remove(string aKey)1043 {1044 if (!m_Dict.ContainsKey(aKey))1045 return null;1046 JSONNode tmp = m_Dict[aKey];1047 m_Dict.Remove(aKey);1048 return tmp;1049 }1050 public override JSONNode Remove(int aIndex)1051 {1052 if (aIndex < 0 || aIndex >= m_Dict.Count)1053 return null;1054 var item = m_Dict.ElementAt(aIndex);1055 m_Dict.Remove(item.Key);1056 return item.Value;1057 }1058 public override JSONNode Remove(JSONNode aNode)1059 {1060 try1061 {1062 var item = m_Dict.Where(k => k.Value == aNode).First();1063 m_Dict.Remove(item.Key);1064 return aNode;1065 }1066 catch1067 {1068 return null;1069 }1070 }1071 public override void Clear()1072 {1073 m_Dict.Clear();1074 }1075 public override JSONNode Clone()1076 {1077 var node = new JSONObject();1078 foreach (var n in m_Dict)1079 {1080 node.Add(n.Key, n.Value.Clone());1081 }1082 return node;1083 }1084 public override bool HasKey(string aKey)1085 {1086 return m_Dict.ContainsKey(aKey);1087 }1088 public override JSONNode GetValueOrDefault(string aKey, JSONNode aDefault)1089 {1090 JSONNode res;1091 if (m_Dict.TryGetValue(aKey, out res))1092 return res;1093 return aDefault;1094 }1095 public override IEnumerable<JSONNode> Children1096 {1097 get1098 {1099 foreach (KeyValuePair<string, JSONNode> N in m_Dict)1100 yield return N.Value;1101 }1102 }1103 internal override void WriteToStringBuilder(StringBuilder aSB, int aIndent, int aIndentInc, JSONTextMode aMode)1104 {1105 aSB.Append('{');1106 bool first = true;1107 if (inline)1108 aMode = JSONTextMode.Compact;1109 foreach (var k in m_Dict)1110 {1111 if (!first)1112 aSB.Append(',');1113 first = false;1114 if (aMode == JSONTextMode.Indent)1115 aSB.AppendLine();1116 if (aMode == JSONTextMode.Indent)1117 aSB.Append(' ', aIndent + aIndentInc);1118 aSB.Append('\"').Append(Escape(k.Key)).Append('\"');1119 if (aMode == JSONTextMode.Compact)1120 aSB.Append(':');1121 else1122 aSB.Append(" : ");1123 k.Value.WriteToStringBuilder(aSB, aIndent + aIndentInc, aIndentInc, aMode);1124 }1125 if (aMode == JSONTextMode.Indent)1126 aSB.AppendLine().Append(' ', aIndent);1127 aSB.Append('}');1128 }1129 }1130 // End of JSONObject1131 public partial class JSONString : JSONNode1132 {1133 private string m_Data;1134 public override JSONNodeType Tag { get { return JSONNodeType.String; } }1135 public override bool IsString { get { return true; } }1136 public override Enumerator GetEnumerator() { return new Enumerator(); }1137 public override string Value1138 {1139 get { return m_Data; }1140 set1141 {1142 m_Data = value;1143 }1144 }1145 public JSONString(string aData)1146 {1147 m_Data = aData;1148 }1149 public override JSONNode Clone()1150 {1151 return new JSONString(m_Data);1152 }1153 internal override void WriteToStringBuilder(StringBuilder aSB, int aIndent, int aIndentInc, JSONTextMode aMode)1154 {1155 aSB.Append('\"').Append(Escape(m_Data)).Append('\"');1156 }1157 public override bool Equals(object obj)1158 {1159 if (base.Equals(obj))1160 return true;1161 string s = obj as string;1162 if (s != null)1163 return m_Data == s;1164 JSONString s2 = obj as JSONString;1165 if (s2 != null)1166 return m_Data == s2.m_Data;1167 return false;1168 }1169 public override int GetHashCode()1170 {1171 return m_Data.GetHashCode();1172 }1173 public override void Clear()1174 {1175 m_Data = "";1176 }1177 }1178 // End of JSONString1179 public partial class JSONNumber : JSONNode1180 {1181 private double m_Data;1182 public override JSONNodeType Tag { get { return JSONNodeType.Number; } }1183 public override bool IsNumber { get { return true; } }1184 public override Enumerator GetEnumerator() { return new Enumerator(); }1185 public override string Value1186 {1187 get { return m_Data.ToString(CultureInfo.InvariantCulture); }1188 set1189 {1190 double v;1191 if (double.TryParse(value, NumberStyles.Float, CultureInfo.InvariantCulture, out v))1192 m_Data = v;1193 }1194 }1195 public override double AsDouble1196 {1197 get { return m_Data; }1198 set { m_Data = value; }1199 }1200 public override long AsLong1201 {1202 get { return (long)m_Data; }1203 set { m_Data = value; }1204 }1205 public override ulong AsULong1206 {1207 get { return (ulong)m_Data; }1208 set { m_Data = value; }1209 }1210 public JSONNumber(double aData)1211 {1212 m_Data = aData;1213 }1214 public JSONNumber(string aData)1215 {1216 Value = aData;1217 }1218 public override JSONNode Clone()1219 {1220 return new JSONNumber(m_Data);1221 }1222 internal override void WriteToStringBuilder(StringBuilder aSB, int aIndent, int aIndentInc, JSONTextMode aMode)1223 {1224 aSB.Append(Value);1225 }1226 private static bool IsNumeric(object value)1227 {1228 return value is int || value is uint1229 || value is float || value is double1230 || value is decimal1231 || value is long || value is ulong1232 || value is short || value is ushort1233 || value is sbyte || value is byte;1234 }1235 public override bool Equals(object obj)1236 {1237 if (obj == null)1238 return false;1239 if (base.Equals(obj))1240 return true;1241 JSONNumber s2 = obj as JSONNumber;1242 if (s2 != null)1243 return m_Data == s2.m_Data;1244 if (IsNumeric(obj))1245 return Convert.ToDouble(obj) == m_Data;1246 return false;1247 }1248 public override int GetHashCode()1249 {1250 return m_Data.GetHashCode();1251 }1252 public override void Clear()1253 {1254 m_Data = 0;1255 }1256 }1257 // End of JSONNumber1258 public partial class JSONBool : JSONNode1259 {1260 private bool m_Data;1261 public override JSONNodeType Tag { get { return JSONNodeType.Boolean; } }1262 public override bool IsBoolean { get { return true; } }1263 public override Enumerator GetEnumerator() { return new Enumerator(); }1264 public override string Value1265 {1266 get { return m_Data.ToString(); }1267 set1268 {1269 bool v;1270 if (bool.TryParse(value, out v))1271 m_Data = v;1272 }1273 }1274 public override bool AsBool1275 {1276 get { return m_Data; }1277 set { m_Data = value; }1278 }1279 public JSONBool(bool aData)1280 {1281 m_Data = aData;1282 }1283 public JSONBool(string aData)1284 {1285 Value = aData;1286 }1287 public override JSONNode Clone()1288 {1289 return new JSONBool(m_Data);1290 }1291 internal override void WriteToStringBuilder(StringBuilder aSB, int aIndent, int aIndentInc, JSONTextMode aMode)1292 {1293 aSB.Append((m_Data) ? "true" : "false");1294 }1295 public override bool Equals(object obj)1296 {1297 if (obj == null)1298 return false;1299 if (obj is bool)1300 return m_Data == (bool)obj;1301 return false;1302 }1303 public override int GetHashCode()1304 {1305 return m_Data.GetHashCode();1306 }1307 public override void Clear()1308 {1309 m_Data = false;1310 }1311 }1312 // End of JSONBool1313 public partial class JSONNull : JSONNode1314 {1315 static JSONNull m_StaticInstance = new JSONNull();1316 public static bool reuseSameInstance = true;1317 public static JSONNull CreateOrGet()1318 {1319 if (reuseSameInstance)1320 return m_StaticInstance;1321 return new JSONNull();...

Full Screen

Full Screen

Clear

Using AI Code Generation

copy

Full Screen

1using System;2using System.Collections.Generic;3using System.Linq;4using System.Text;5using System.Threading.Tasks;6using SimpleJSON;7{8 {9 static void Main(string[] args)10 {11{12 { ""name"": ""Ford"", ""models"": [""Fiesta"", ""Focus"", ""Mustang""] },13 { ""name"": ""BMW"", ""models"": [""320"", ""X3"", ""X5""] },14 { ""name"": ""Fiat"", ""models"": [""500"", ""Panda""] }15}";16 var j = JSON.Parse(json);17 var cars = j["cars"].Children();18 foreach (var car in cars)19 {20 Console.WriteLine(car["name"]);21 foreach (var model in car["models"].Children())22 {23 Console.WriteLine(model);24 }25 }26 }27 }28}29using System;30using System.Collections.Generic;31using System.Linq;32using System.Text;33using System.Threading.Tasks;34using SimpleJSON;35{36 {37 static void Main(string[] args)38 {39{40 { ""name"": ""Ford"", ""models"": [""Fiesta"", ""Focus"", ""Mustang""] },41 { ""name"": ""BMW"", ""models"": [""320"", ""X3"", ""X5""] },42 { ""name"": ""Fiat"", ""models"": [""500"", ""Panda""] }43}";44 var j = JSON.Parse(json);45 var cars = j["cars"].Children();46 foreach (var car in cars)47 {48 Console.WriteLine(car["name"]);49 foreach (var model in car["models"].Children())50 {51 Console.WriteLine(model);52 }53 }54 }55 }56}

Full Screen

Full Screen

Clear

Using AI Code Generation

copy

Full Screen

1using System;2using System.Collections.Generic;3using System.Linq;4using System.Text;5using System.Threading.Tasks;6using SimpleJSON;7{8 {9 static void Main(string[] args)10 {11 var json = new JSONObject();12 json.Add("Name", "Rakesh");13 json.Add("Age", 24);14 json.Add("City", "Bangalore");15 foreach (var item in json)16 {17 Console.WriteLine(item.Key + " : " + item.Value);18 }19 Console.WriteLine("-------------------------------");20 json.Clear();21 foreach (var item in json)22 {23 Console.WriteLine(item.Key + " : " + item.Value);24 }25 Console.ReadLine();26 }27 }28}29using System;30using System.Collections.Generic;31using System.Linq;32using System.Text;33using System.Threading.Tasks;34using SimpleJSON;35{36 {37 static void Main(string[] args)38 {39 var json = new JSONArray();40 json.Add("Rakesh");41 json.Add(24);42 json.Add("Bangalore");43 foreach (var item in json)44 {45 Console.WriteLine(item);46 }47 Console.WriteLine("-------------------------------");48 json.Clear();49 foreach (var item in json)50 {51 Console.WriteLine(item);

Full Screen

Full Screen

Clear

Using AI Code Generation

copy

Full Screen

1using System;2using System.Collections.Generic;3using System.Linq;4using System.Text;5using System.Threading.Tasks;6using SimpleJSON;7{8 {9 static void Main(string[] args)10 {11 JSONNode json = JSON.Parse(@"{""key1"": ""value1"", ""key2"": ""value2""}");12 var enumerator = json.GetEnumerator();13 enumerator.MoveNext();14 enumerator.MoveNext();15 enumerator.Clear();16 Console.WriteLine(json.ToString());17 Console.ReadKey();18 }19 }20}21{"key1":"value1"}

Full Screen

Full Screen

Clear

Using AI Code Generation

copy

Full Screen

1using System;2using System.Collections.Generic;3using System.Linq;4using System.Text;5using System.Threading.Tasks;6using SimpleJSON;7{8 {9 static void Main(string[] args)10 {11 string json = @"{""id"": 1, ""name"": ""John"", ""age"": 30, ""cars"": [""Ford"", ""BMW"", ""Fiat""]}";12 var obj = JSON.Parse(json);13 var cars = obj["cars"].AsArray;14 cars.Clear();15 Console.WriteLine(obj.ToString());16 }17 }18}19{20}21using System;22using System.Collections.Generic;23using System.Linq;24using System.Text;25using System.Threading.Tasks;26using SimpleJSON;27{28 {29 static void Main(string[] args)30 {31 string json = @"{""id"": 1, ""name"": ""John"", ""age"": 30, ""cars"": [""Ford"", ""BMW"", ""Fiat""]}";32 var obj = JSON.Parse(json);33 Console.WriteLine(obj.ToString());34 }35 }36}37{38}39using System;40using System.Collections.Generic;41using System.Linq;42using System.Text;43using System.Threading.Tasks;44using SimpleJSON;45{46 {47 static void Main(string[] args)48 {49 string json = @"{""id"": 1, ""name"": ""John"", ""age"": 30, ""cars"": [""Ford"", ""BMW"", ""Fiat""]}";50 var obj = JSON.Parse(json);51 var cars = obj["cars"].AsArray;52 Console.WriteLine(cars.ToString());53 }54 }55}56using System;57using System.Collections.Generic;58using System.Linq;

Full Screen

Full Screen

Clear

Using AI Code Generation

copy

Full Screen

1using System;2using System.Collections.Generic;3using System.Linq;4using System.Text;5using SimpleJSON;6{7 {8 static void Main(string[] args)9 {10 JSONNode node = JSON.Parse(@"{11 { ""name"" : ""Ford"", ""models"" : [ ""Fiesta"", ""Focus"", ""Mustang"" ] },12 { ""name"" : ""BMW"", ""models"" : [ ""320"", ""X3"", ""X5"" ] },13 { ""name"" : ""Fiat"", ""models"" : [ ""500"", ""Panda"" ] }14}");15 JSONNode cars = node["cars"];16 foreach (JSONNode car in cars)17 {18 Console.WriteLine(car["name"]);19 foreach (JSONNode model in car["models"])20 {21 Console.WriteLine(model);22 }23 }24 Console.ReadLine();25 }26 }27}28using System;29using System.Collections.Generic;30using System.Linq;31using System.Text;32using SimpleJSON;33{34 {35 static void Main(string[] args)36 {37 JSONNode node = JSON.Parse(@"{38 { ""name"" : ""Ford"", ""models"" : [ ""Fiesta"", ""Focus"", ""Mustang"" ] },39 { ""name"" : ""BMW"", ""models"" : [ ""320"", ""X3"", ""X5"" ] },40 { ""name"" : ""Fiat"", ""models"" : [ ""500"", ""Panda"" ] }41}");42 JSONNode cars = node["cars"];43 foreach (JSONNode car in cars)44 {45 Console.WriteLine(car["name"]);46 foreach (JSONNode model in car["models"])47 {48 Console.WriteLine(model);49 }50 }51 Console.ReadLine();52 }53 }54}55using System;56using System.Collections.Generic;57using System.Linq;58using System.Text;59using SimpleJSON;60{61 {62 static void Main(string

Full Screen

Full Screen

Clear

Using AI Code Generation

copy

Full Screen

1using SimpleJSON;2using System;3using System.Collections.Generic;4using System.Linq;5using System.Text;6using System.Threading.Tasks;7{8 {9 public static void Main(string[] args)10 {11 string json = @"{12 ""Address"": {13 }14 }";15 var jObject = JSON.Parse(json);16 jObject.Clear();17 Console.WriteLine(jObject.ToString());18 Console.ReadLine();19 }20 }21}22{}23using SimpleJSON;24using System;25using System.Collections.Generic;26using System.Linq;27using System.Text;28using System.Threading.Tasks;29{30 {31 public static void Main(string[] args)32 {33 string json = @"{34 ""Address"": {35 }36 }";37 var jObject = JSON.Parse(json);38 jObject.Remove("Name");39 Console.WriteLine(jObject.ToString());40 Console.ReadLine();41 }42 }43}44{45 "Address": {46 }47}48using SimpleJSON;49using System;50using System.Collections.Generic;51using System.Linq;52using System.Text;53using System.Threading.Tasks;54{55 {56 public static void Main(string[] args)57 {58 string json = @"{59 ""Address"": {60 }61 }";62 var jObject = JSON.Parse(json);63 jObject.Replace("Name", "Smith");64 Console.WriteLine(jObject.ToString());65 Console.ReadLine();66 }67 }68}69{70 "Address": {71 },

Full Screen

Full Screen

Clear

Using AI Code Generation

copy

Full Screen

1using System;2using System.Collections.Generic;3using System.Linq;4using System.Text;5using SimpleJSON;6{7 {8 static void Main(string[] args)9 {10 string json = @"{11 }";12 var j = JSON.Parse(json);13 var e = j.GetEnumerator();14 while (e.MoveNext())15 {16 Console.WriteLine(e.Current.Key + " : " + e.Current.Value);17 }18 e.Clear();19 while (e.MoveNext())20 {21 Console.WriteLine(e.Current.Key + " : " + e.Current.Value);22 }23 }24 }25}26public bool MoveNext()

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful