Skip to content

Instantly share code, notes, and snippets.

@IanWold
Last active November 9, 2022 21:23
Show Gist options
  • Save IanWold/320527877e5af2d8ebe356edd7b7e4c1 to your computer and use it in GitHub Desktop.
Save IanWold/320527877e5af2d8ebe356edd7b7e4c1 to your computer and use it in GitHub Desktop.
public class JSONValue {}
public class JSONObject : JSONValue
{
public Dictionary<string, JSONValue> Pairs { get; set; }
public JSONObject(IEnumerable<KeyValuePair<string, JSONValue>> pairs)
{
Pairs = new Dictionary<string, JSONValue>();
if (pairs != null)
{
foreach (var p in pairs)
{
Pairs.Add(p.Key, p.Value);
}
}
}
}
public class JSONArray : JSONValue
{
public List<JSONValue> Elements { get; set; }
public JSONArray(IEnumerable<JSONValue> elements)
{
Elements = new List<JSONValue>();
if (elements != null)
{
foreach (var e in elements)
{
Elements.Add(e);
}
}
}
}
public class JSONLiteral : JSONValue
{
public string Value { get; set; }
public LiteralType ValueType { get; set; }
public JSONLiteral(string value, LiteralType type)
{
Value = value;
ValueType = type;
}
pubilc static enum LiteralType
{
String,
Number,
Boolean,
Null
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment