Interhaptics SDK for Unity 1.6
Loading...
Searching...
No Matches
SimpleJSON.JSONNode Class Referenceabstract
Inheritance diagram for SimpleJSON.JSONNode:
SimpleJSON.JSONArray SimpleJSON.JSONBool SimpleJSON.JSONNull SimpleJSON.JSONNumber SimpleJSON.JSONObject SimpleJSON.JSONString

Classes

struct  Enumerator
 
struct  KeyEnumerator
 
class  LinqEnumerator
 
struct  ValueEnumerator
 

Public Member Functions

virtual void Add (string aKey, JSONNode aItem)
 
virtual void Add (JSONNode aItem)
 
virtual JSONNode Remove (string aKey)
 
virtual JSONNode Remove (int aIndex)
 
virtual JSONNode Remove (JSONNode aNode)
 
virtual JSONNode Clone ()
 
virtual bool HasKey (string aKey)
 
virtual JSONNode GetValueOrDefault (string aKey, JSONNode aDefault)
 
override string ToString ()
 
virtual string ToString (int aIndent)
 
Enumerator GetEnumerator ()
 
override bool Equals (object obj)
 
override int GetHashCode ()
 

Static Public Member Functions

static implicit operator JSONNode (string s)
 
static implicit operator string (JSONNode d)
 
static implicit operator JSONNode (double n)
 
static implicit operator double (JSONNode d)
 
static implicit operator JSONNode (float n)
 
static implicit operator float (JSONNode d)
 
static implicit operator JSONNode (int n)
 
static implicit operator int (JSONNode d)
 
static implicit operator JSONNode (long n)
 
static implicit operator long (JSONNode d)
 
static implicit operator JSONNode (bool b)
 
static implicit operator bool (JSONNode d)
 
static implicit operator JSONNode (KeyValuePair< string, JSONNode > aKeyValue)
 
static bool operator== (JSONNode a, object b)
 
static bool operator!= (JSONNode a, object b)
 
static JSONNode Parse (string aJSON)
 

Static Public Attributes

static bool forceASCII = false
 
static bool longAsString = false
 
static bool allowLineComments = true
 

Properties

JSONNodeType Tag [get]
 
virtual JSONNode this[int aIndex] [get, set]
 
virtual JSONNode this[string aKey] [get, set]
 
virtual string Value [get, set]
 
virtual int Count [get]
 
virtual bool IsNumber [get]
 
virtual bool IsString [get]
 
virtual bool IsBoolean [get]
 
virtual bool IsNull [get]
 
virtual bool IsArray [get]
 
virtual bool IsObject [get]
 
virtual bool Inline [get, set]
 
virtual IEnumerable< JSONNodeChildren [get]
 
IEnumerable< JSONNodeDeepChildren [get]
 
IEnumerable< KeyValuePair< string, JSONNode > > Linq [get]
 
KeyEnumerator Keys [get]
 
ValueEnumerator Values [get]
 
virtual double AsDouble [get, set]
 
virtual int AsInt [get, set]
 
virtual float AsFloat [get, set]
 
virtual bool AsBool [get, set]
 
virtual long AsLong [get, set]
 
virtual JSONArray AsArray [get]
 
virtual JSONObject AsObject [get]
 

Detailed Description

Definition at line 63 of file SimpleJSON.cs.

Member Function Documentation

◆ Add() [1/2]

virtual void SimpleJSON.JSONNode.Add ( JSONNode aItem)
virtual

Definition at line 193 of file SimpleJSON.cs.

194 {
195 Add("", aItem);
196 }
virtual void Add(string aKey, JSONNode aItem)

References SimpleJSON.JSONNode.Add().

◆ Add() [2/2]

virtual void SimpleJSON.JSONNode.Add ( string aKey,
JSONNode aItem )
virtual

◆ Clone()

virtual JSONNode SimpleJSON.JSONNode.Clone ( )
virtual

Reimplemented in SimpleJSON.JSONArray, SimpleJSON.JSONBool, SimpleJSON.JSONNull, SimpleJSON.JSONNumber, SimpleJSON.JSONObject, and SimpleJSON.JSONString.

Definition at line 213 of file SimpleJSON.cs.

214 {
215 return null;
216 }

◆ Equals()

override bool SimpleJSON.JSONNode.Equals ( object obj)

Definition at line 426 of file SimpleJSON.cs.

427 {
428 return ReferenceEquals(this, obj);
429 }

Referenced by SimpleJSON.JSONNode.operator==().

◆ GetEnumerator()

Enumerator SimpleJSON.JSONNode.GetEnumerator ( )
abstract

◆ GetHashCode()

override int SimpleJSON.JSONNode.GetHashCode ( )

Definition at line 431 of file SimpleJSON.cs.

432 {
433 return base.GetHashCode();
434 }

◆ GetValueOrDefault()

virtual JSONNode SimpleJSON.JSONNode.GetValueOrDefault ( string aKey,
JSONNode aDefault )
virtual

Reimplemented in SimpleJSON.JSONObject.

Definition at line 241 of file SimpleJSON.cs.

242 {
243 return aDefault;
244 }

◆ HasKey()

virtual bool SimpleJSON.JSONNode.HasKey ( string aKey)
virtual

Reimplemented in SimpleJSON.JSONObject.

Definition at line 236 of file SimpleJSON.cs.

237 {
238 return false;
239 }

◆ operator bool()

static implicit SimpleJSON.JSONNode.operator bool ( JSONNode d)
static

Definition at line 400 of file SimpleJSON.cs.

401 {
402 return (d == null) ? false : d.AsBool;
403 }

References SimpleJSON.JSONNode.AsBool.

◆ operator double()

static implicit SimpleJSON.JSONNode.operator double ( JSONNode d)
static

Definition at line 362 of file SimpleJSON.cs.

363 {
364 return (d == null) ? 0 : d.AsDouble;
365 }

References SimpleJSON.JSONNode.AsDouble.

◆ operator float()

static implicit SimpleJSON.JSONNode.operator float ( JSONNode d)
static

Definition at line 371 of file SimpleJSON.cs.

372 {
373 return (d == null) ? 0 : d.AsFloat;
374 }

References SimpleJSON.JSONNode.AsFloat.

◆ operator int()

static implicit SimpleJSON.JSONNode.operator int ( JSONNode d)
static

Definition at line 380 of file SimpleJSON.cs.

381 {
382 return (d == null) ? 0 : d.AsInt;
383 }

References SimpleJSON.JSONNode.AsInt.

◆ operator JSONNode() [1/7]

static implicit SimpleJSON.JSONNode.operator JSONNode ( bool b)
static

Definition at line 396 of file SimpleJSON.cs.

397 {
398 return new JSONBool(b);
399 }

◆ operator JSONNode() [2/7]

static implicit SimpleJSON.JSONNode.operator JSONNode ( double n)
static

Definition at line 358 of file SimpleJSON.cs.

359 {
360 return new JSONNumber(n);
361 }

◆ operator JSONNode() [3/7]

static implicit SimpleJSON.JSONNode.operator JSONNode ( float n)
static

Definition at line 367 of file SimpleJSON.cs.

368 {
369 return new JSONNumber(n);
370 }

◆ operator JSONNode() [4/7]

static implicit SimpleJSON.JSONNode.operator JSONNode ( int n)
static

Definition at line 376 of file SimpleJSON.cs.

377 {
378 return new JSONNumber(n);
379 }

◆ operator JSONNode() [5/7]

static implicit SimpleJSON.JSONNode.operator JSONNode ( KeyValuePair< string, JSONNode > aKeyValue)
static

Definition at line 405 of file SimpleJSON.cs.

406 {
407 return aKeyValue.Value;
408 }

References SimpleJSON.JSONNode.Value.

◆ operator JSONNode() [6/7]

static implicit SimpleJSON.JSONNode.operator JSONNode ( long n)
static

Definition at line 385 of file SimpleJSON.cs.

386 {
387 if (longAsString)
388 return new JSONString(n.ToString());
389 return new JSONNumber(n);
390 }
static bool longAsString

References SimpleJSON.JSONNode.longAsString.

◆ operator JSONNode() [7/7]

static implicit SimpleJSON.JSONNode.operator JSONNode ( string s)
static

Definition at line 349 of file SimpleJSON.cs.

350 {
351 return new JSONString(s);
352 }

◆ operator long()

static implicit SimpleJSON.JSONNode.operator long ( JSONNode d)
static

Definition at line 391 of file SimpleJSON.cs.

392 {
393 return (d == null) ? 0L : d.AsLong;
394 }

References SimpleJSON.JSONNode.AsLong.

◆ operator string()

static implicit SimpleJSON.JSONNode.operator string ( JSONNode d)
static

Definition at line 353 of file SimpleJSON.cs.

354 {
355 return (d == null) ? null : d.Value;
356 }

References SimpleJSON.JSONNode.Value.

◆ operator!=()

static bool SimpleJSON.JSONNode.operator!= ( JSONNode a,
object b )
static

Definition at line 421 of file SimpleJSON.cs.

422 {
423 return !(a == b);
424 }

◆ operator==()

static bool SimpleJSON.JSONNode.operator== ( JSONNode a,
object b )
static

Definition at line 410 of file SimpleJSON.cs.

411 {
412 if (ReferenceEquals(a, b))
413 return true;
414 bool aIsNull = a is JSONNull || ReferenceEquals(a, null) || a is JSONLazyCreator;
415 bool bIsNull = b is JSONNull || ReferenceEquals(b, null) || b is JSONLazyCreator;
416 if (aIsNull && bIsNull)
417 return true;
418 return !aIsNull && a.Equals(b);
419 }

References SimpleJSON.JSONNode.Equals().

◆ Parse()

static JSONNode SimpleJSON.JSONNode.Parse ( string aJSON)
static

Definition at line 512 of file SimpleJSON.cs.

513 {
514 Stack<JSONNode> stack = new Stack<JSONNode>();
515 JSONNode ctx = null;
516 int i = 0;
517 StringBuilder Token = new StringBuilder();
518 string TokenName = "";
519 bool QuoteMode = false;
520 bool TokenIsQuoted = false;
521 while (i < aJSON.Length)
522 {
523 switch (aJSON[i])
524 {
525 case '{':
526 if (QuoteMode)
527 {
528 Token.Append(aJSON[i]);
529 break;
530 }
531 stack.Push(new JSONObject());
532 if (ctx != null)
533 {
534 ctx.Add(TokenName, stack.Peek());
535 }
536 TokenName = "";
537 Token.Length = 0;
538 ctx = stack.Peek();
539 break;
540
541 case '[':
542 if (QuoteMode)
543 {
544 Token.Append(aJSON[i]);
545 break;
546 }
547
548 stack.Push(new JSONArray());
549 if (ctx != null)
550 {
551 ctx.Add(TokenName, stack.Peek());
552 }
553 TokenName = "";
554 Token.Length = 0;
555 ctx = stack.Peek();
556 break;
557
558 case '}':
559 case ']':
560 if (QuoteMode)
561 {
562
563 Token.Append(aJSON[i]);
564 break;
565 }
566 if (stack.Count == 0)
567 throw new Exception("JSON Parse: Too many closing brackets");
568
569 stack.Pop();
570 if (Token.Length > 0 || TokenIsQuoted)
571 ctx.Add(TokenName, ParseElement(Token.ToString(), TokenIsQuoted));
572 TokenIsQuoted = false;
573 TokenName = "";
574 Token.Length = 0;
575 if (stack.Count > 0)
576 ctx = stack.Peek();
577 break;
578
579 case ':':
580 if (QuoteMode)
581 {
582 Token.Append(aJSON[i]);
583 break;
584 }
585 TokenName = Token.ToString();
586 Token.Length = 0;
587 TokenIsQuoted = false;
588 break;
589
590 case '"':
591 QuoteMode ^= true;
592 TokenIsQuoted |= QuoteMode;
593 break;
594
595 case ',':
596 if (QuoteMode)
597 {
598 Token.Append(aJSON[i]);
599 break;
600 }
601 if (Token.Length > 0 || TokenIsQuoted)
602 ctx.Add(TokenName, ParseElement(Token.ToString(), TokenIsQuoted));
603 TokenIsQuoted = false;
604 TokenName = "";
605 Token.Length = 0;
606 TokenIsQuoted = false;
607 break;
608
609 case '\r':
610 case '\n':
611 break;
612
613 case ' ':
614 case '\t':
615 if (QuoteMode)
616 Token.Append(aJSON[i]);
617 break;
618
619 case '\\':
620 ++i;
621 if (QuoteMode)
622 {
623 char C = aJSON[i];
624 switch (C)
625 {
626 case 't':
627 Token.Append('\t');
628 break;
629 case 'r':
630 Token.Append('\r');
631 break;
632 case 'n':
633 Token.Append('\n');
634 break;
635 case 'b':
636 Token.Append('\b');
637 break;
638 case 'f':
639 Token.Append('\f');
640 break;
641 case 'u':
642 {
643 string s = aJSON.Substring(i + 1, 4);
644 Token.Append((char)int.Parse(
645 s,
646 System.Globalization.NumberStyles.AllowHexSpecifier));
647 i += 4;
648 break;
649 }
650 default:
651 Token.Append(C);
652 break;
653 }
654 }
655 break;
656 case '/':
657 if (allowLineComments && !QuoteMode && i + 1 < aJSON.Length && aJSON[i + 1] == '/')
658 {
659 while (++i < aJSON.Length && aJSON[i] != '\n' && aJSON[i] != '\r') ;
660 break;
661 }
662 Token.Append(aJSON[i]);
663 break;
664 case '\uFEFF': // remove / ignore BOM (Byte Order Mark)
665 break;
666
667 default:
668 Token.Append(aJSON[i]);
669 break;
670 }
671 ++i;
672 }
673 if (QuoteMode)
674 {
675 throw new Exception("JSON Parse: Quotation marks seems to be messed up.");
676 }
677 if (ctx == null)
678 return ParseElement(Token.ToString(), TokenIsQuoted);
679 return ctx;
680 }
static bool allowLineComments
static JSONNode Parse(string aJSON)

References SimpleJSON.JSONNode.Add(), SimpleJSON.JSONNode.allowLineComments, SimpleJSON.JSONNode.Parse(), and SimpleJSON.JSONNode.ToString().

Referenced by SimpleJSON.JSONNode.Parse().

◆ Remove() [1/3]

virtual JSONNode SimpleJSON.JSONNode.Remove ( int aIndex)
virtual

Reimplemented in SimpleJSON.JSONArray, and SimpleJSON.JSONObject.

Definition at line 203 of file SimpleJSON.cs.

204 {
205 return null;
206 }

◆ Remove() [2/3]

virtual JSONNode SimpleJSON.JSONNode.Remove ( JSONNode aNode)
virtual

Reimplemented in SimpleJSON.JSONArray, and SimpleJSON.JSONObject.

Definition at line 208 of file SimpleJSON.cs.

209 {
210 return aNode;
211 }

◆ Remove() [3/3]

virtual JSONNode SimpleJSON.JSONNode.Remove ( string aKey)
virtual

Reimplemented in SimpleJSON.JSONObject.

Definition at line 198 of file SimpleJSON.cs.

199 {
200 return null;
201 }

Referenced by SimpleJSON.JSONArray.Remove(), SimpleJSON.JSONObject.Remove(), SimpleJSON.JSONObject.Remove(), and SimpleJSON.JSONObject.Remove().

◆ ToString() [1/2]

override string SimpleJSON.JSONNode.ToString ( )

Definition at line 246 of file SimpleJSON.cs.

247 {
248 StringBuilder sb = new StringBuilder();
249 WriteToStringBuilder(sb, 0, 0, JSONTextMode.Compact);
250 return sb.ToString();
251 }

Referenced by SimpleJSON.JSONNode.Parse().

◆ ToString() [2/2]

virtual string SimpleJSON.JSONNode.ToString ( int aIndent)
virtual

Definition at line 253 of file SimpleJSON.cs.

254 {
255 StringBuilder sb = new StringBuilder();
256 WriteToStringBuilder(sb, 0, aIndent, JSONTextMode.Indent);
257 return sb.ToString();
258 }

Member Data Documentation

◆ allowLineComments

bool SimpleJSON.JSONNode.allowLineComments = true
static

Definition at line 169 of file SimpleJSON.cs.

Referenced by SimpleJSON.JSONNode.Parse().

◆ forceASCII

bool SimpleJSON.JSONNode.forceASCII = false
static

Definition at line 167 of file SimpleJSON.cs.

◆ longAsString

bool SimpleJSON.JSONNode.longAsString = false
static

Definition at line 168 of file SimpleJSON.cs.

Referenced by SimpleJSON.JSONNode.operator JSONNode().

Property Documentation

◆ AsArray

virtual JSONArray SimpleJSON.JSONNode.AsArray
get

Definition at line 328 of file SimpleJSON.cs.

329 {
330 get
331 {
332 return this as JSONArray;
333 }
334 }

◆ AsBool

virtual bool SimpleJSON.JSONNode.AsBool
getset

Definition at line 298 of file SimpleJSON.cs.

299 {
300 get
301 {
302 bool v = false;
303 if (bool.TryParse(Value, out v))
304 return v;
305 return !string.IsNullOrEmpty(Value);
306 }
307 set
308 {
309 Value = (value) ? "true" : "false";
310 }
311 }
virtual string Value

Referenced by SimpleJSON.JSONNode.operator bool().

◆ AsDouble

virtual double SimpleJSON.JSONNode.AsDouble
getset

Definition at line 271 of file SimpleJSON.cs.

272 {
273 get
274 {
275 double v = 0.0;
276 if (double.TryParse(Value, NumberStyles.Float, CultureInfo.InvariantCulture, out v))
277 return v;
278 return 0.0;
279 }
280 set
281 {
282 Value = value.ToString(CultureInfo.InvariantCulture);
283 }
284 }

Referenced by SimpleJSON.JSONNode.operator double().

◆ AsFloat

virtual float SimpleJSON.JSONNode.AsFloat
getset

Definition at line 292 of file SimpleJSON.cs.

293 {
294 get { return (float)AsDouble; }
295 set { AsDouble = value; }
296 }
virtual double AsDouble

Referenced by SimpleJSON.JSONNode.operator float().

◆ AsInt

virtual int SimpleJSON.JSONNode.AsInt
getset

Definition at line 286 of file SimpleJSON.cs.

287 {
288 get { return (int)AsDouble; }
289 set { AsDouble = value; }
290 }

Referenced by SimpleJSON.JSONNode.operator int().

◆ AsLong

virtual long SimpleJSON.JSONNode.AsLong
getset

Definition at line 313 of file SimpleJSON.cs.

314 {
315 get
316 {
317 long val = 0;
318 if (long.TryParse(Value, out val))
319 return val;
320 return 0L;
321 }
322 set
323 {
324 Value = value.ToString();
325 }
326 }

Referenced by SimpleJSON.JSONNode.operator long().

◆ AsObject

virtual JSONObject SimpleJSON.JSONNode.AsObject
get

Definition at line 336 of file SimpleJSON.cs.

337 {
338 get
339 {
340 return this as JSONObject;
341 }
342 }

◆ Children

virtual IEnumerable<JSONNode> SimpleJSON.JSONNode.Children
get

Definition at line 218 of file SimpleJSON.cs.

219 {
220 get
221 {
222 yield break;
223 }
224 }

◆ Count

virtual int SimpleJSON.JSONNode.Count
get

Definition at line 179 of file SimpleJSON.cs.

179{ get { return 0; } }

◆ DeepChildren

IEnumerable<JSONNode> SimpleJSON.JSONNode.DeepChildren
get

Definition at line 226 of file SimpleJSON.cs.

227 {
228 get
229 {
230 foreach (var C in Children)
231 foreach (var D in C.DeepChildren)
232 yield return D;
233 }
234 }
virtual IEnumerable< JSONNode > Children

◆ Inline

virtual bool SimpleJSON.JSONNode.Inline
getset

Definition at line 188 of file SimpleJSON.cs.

188{ get { return false; } set { } }

◆ IsArray

virtual bool SimpleJSON.JSONNode.IsArray
get

Definition at line 185 of file SimpleJSON.cs.

185{ get { return false; } }

◆ IsBoolean

virtual bool SimpleJSON.JSONNode.IsBoolean
get

Definition at line 183 of file SimpleJSON.cs.

183{ get { return false; } }

◆ IsNull

virtual bool SimpleJSON.JSONNode.IsNull
get

Definition at line 184 of file SimpleJSON.cs.

184{ get { return false; } }

◆ IsNumber

virtual bool SimpleJSON.JSONNode.IsNumber
get

Definition at line 181 of file SimpleJSON.cs.

181{ get { return false; } }

◆ IsObject

virtual bool SimpleJSON.JSONNode.IsObject
get

Definition at line 186 of file SimpleJSON.cs.

186{ get { return false; } }

◆ IsString

virtual bool SimpleJSON.JSONNode.IsString
get

Definition at line 182 of file SimpleJSON.cs.

182{ get { return false; } }

◆ Keys

KeyEnumerator SimpleJSON.JSONNode.Keys
get

Definition at line 263 of file SimpleJSON.cs.

263{ get { return new KeyEnumerator(GetEnumerator()); } }
Enumerator GetEnumerator()

◆ Linq

IEnumerable<KeyValuePair<string, JSONNode> > SimpleJSON.JSONNode.Linq
get

Definition at line 262 of file SimpleJSON.cs.

262{ get { return new LinqEnumerator(this); } }

◆ Tag

JSONNodeType SimpleJSON.JSONNode.Tag
getabstract

Definition at line 171 of file SimpleJSON.cs.

171{ get; }

◆ this[int aIndex]

virtual JSONNode SimpleJSON.JSONNode.this[int aIndex]
getset

Definition at line 173 of file SimpleJSON.cs.

173{ get { return null; } set { } }

◆ this[string aKey]

virtual JSONNode SimpleJSON.JSONNode.this[string aKey]
getset

Definition at line 175 of file SimpleJSON.cs.

175{ get { return null; } set { } }

◆ Value

virtual string SimpleJSON.JSONNode.Value
getset

Definition at line 177 of file SimpleJSON.cs.

177{ get { return ""; } set { } }

Referenced by SimpleJSON.JSONNode.operator JSONNode(), SimpleJSON.JSONNode.operator string(), and SimpleJSON.JSONObject.Remove().

◆ Values

ValueEnumerator SimpleJSON.JSONNode.Values
get

Definition at line 264 of file SimpleJSON.cs.

264{ get { return new ValueEnumerator(GetEnumerator()); } }

The documentation for this class was generated from the following file: