public static JSONObj Create(AddJSONContents content) { JSONObj obj = Create(); content.Invoke(obj); return(obj); }
public static JSONObj Create() { #if POOLING JSONObj result = null; while (result == null && releaseQueue.Count > 0) { result = releaseQueue.Dequeue(); #if DEV //The following cases should NEVER HAPPEN (but they do...) if (result == null) { Debug.WriteLine("wtf " + releaseQueue.Count); } else if (result.list != null) { Debug.WriteLine("wtflist " + result.list.Count); } #endif } if (result != null) { return(result); } #endif return(new JSONObj()); }
/* * Vector2 */ public static Vector2 ToVector2(JSONObj obj) { float x = obj["x"] ? obj["x"].f : 0; float y = obj["y"] ? obj["y"].f : 0; return(new Vector2(x, y)); }
public bool TryGetVector(string baseName, out Vector3 vector) { vector = new Vector3(); if (Attributes.ContainsKey(baseName)) { JSONObj Value = Attributes[baseName]; if (Value != null && Value.IsObject) { for (int i = 0; i < Value.list.Count; i++) { if (Value.list[i].IsNumber) { if (Value.keys[i] == "x") { vector.x = Value.list[i].f; } else if (Value.keys[i] == "y") { vector.y = Value.list[i].f; } else if (Value.keys[i] == "z") { vector.z = Value.list[i].f; } } } return(true); } } return(false); }
public static JSONObj Serialize(QueryNode node) { JSONObj masterObj = new JSONObj(JSONObj.ObjectType.OBJECT); masterObj.AddField("type", node.Type.ToString().ToLower()); masterObj.AddField("op", node.Operator.ToString().ToLower()); switch (node.Type) { case QueryNodeType.Group: JSONObj innerObj = new JSONObj(JSONObj.ObjectType.ARRAY); foreach (QueryNode Item in node.Children) { innerObj.Add(Serialize(Item)); } masterObj.AddField("children", innerObj); break; case QueryNodeType.Comparison: masterObj.AddField("column", node.Column); masterObj.AddField("value", node.Value); break; } string test = masterObj.ToString(); return(masterObj); }
/// <summary> /// Create a JSONObj by parsing string data /// </summary> /// <param name="val">The string to be parsed</param> /// <param name="maxDepth">The maximum depth for the parser to search. Set this to to 1 for the first level, /// 2 for the first 2 levels, etc. It defaults to -2 because -1 is the depth value that is parsed (see below)</param> /// <param name="storeExcessLevels">Whether to store levels beyond maxDepth in baked JSONObjs</param> /// <param name="strict">Whether to be strict in the parsing. For example, non-strict parsing will successfully /// parse "a string" into a string-type </param> /// <returns></returns> public static JSONObj Create(string val, int maxDepth = -2, bool storeExcessLevels = false, bool strict = false) { JSONObj obj = Create(); obj.Parse(val, maxDepth, storeExcessLevels, strict); return(obj); }
public void AddField(string name, JSONObj obj) { if (obj) //Don't do anything if the object is null { if (type != ObjectType.OBJECT) { if (keys == null) { keys = new List <string>(); } if (type == ObjectType.ARRAY) { for (int i = 0; i < list.Count; i++) { keys.Add(i.ToString(CultureInfo.InvariantCulture)); } } else if (list == null) { list = new List <JSONObj>(); } type = ObjectType.OBJECT; //Congratulations, son, you're an OBJECT now } keys.Add(name); list.Add(obj); } }
/* * Layer Mask */ public static JSONObj FromLayerMask(LayerMask l) { JSONObj result = JSONObj.obj; result.AddField("value", l.value); return(result); }
// Overload for grouping nodes (AND, OR) public QueryNode(QueryNodeType type, QueryOp op, QueryNodeList childNodes) { this.Type = type; this.Operator = op; this.Column = ""; this.Value = JSONObj.nullJO; this.Children = childNodes; }
public static JSONObj Create(float val) { JSONObj obj = Create(); obj.type = ObjectType.NUMBER; obj.n = val; return(obj); }
public static JSONObj CreateStringObject(string val) { JSONObj obj = Create(); obj.type = ObjectType.STRING; obj.str = val; return(obj); }
// Standard single value node public QueryNode(QueryNodeType type, string column, QueryOp op, JSONObj value) { this.Type = type; this.Column = column; this.Operator = op; this.Value = value; this.Children = new QueryNodeList(); }
public static JSONObj CreateBakedObject(string val) { JSONObj bakedObject = Create(); bakedObject.type = ObjectType.BAKED; bakedObject.str = val; return(bakedObject); }
public static JSONObj Create(bool val) { JSONObj obj = Create(); obj.type = ObjectType.BOOL; obj.b = val; return(obj); }
public static Vector3 ToVector3(JSONObj obj) { float x = obj["x"] ? obj["x"].f : 0; float y = obj["y"] ? obj["y"].f : 0; float z = obj["z"] ? obj["z"].f : 0; return(new Vector3(x, y, z)); }
public static LayerMask ToLayerMask(JSONObj obj) { LayerMask l = new LayerMask { value = (int)obj["value"].n }; return(l); }
public QueryEvent(JSONObj jObj) { Debug.Assert(jObj.IsObject); for (int i = 0; i < jObj.keys.Count; i++) { this.Attributes.Add(jObj.keys[i], jObj.list[i]); } }
public static Quaternion ToQuaternion(JSONObj obj) { float x = obj["x"] ? obj["x"].f : 0; float y = obj["y"] ? obj["y"].f : 0; float z = obj["z"] ? obj["z"].f : 0; float w = obj["w"] ? obj["w"].f : 0; return(new Quaternion(x, y, z, w)); }
public static Vector4 ToVector4(JSONObj obj) { float x = obj["x"] ? obj["x"].f : 0; float y = obj["y"] ? obj["y"].f : 0; float z = obj["z"] ? obj["z"].f : 0; float w = obj["w"] ? obj["w"].f : 0; return(new Vector4(x, y, z, w)); }
public void SetField(string name, JSONObj obj) { if (HasField(name)) { list.Remove(this[name]); keys.Remove(name); } AddField(name, obj); }
public TelemetryBatchPayload(TelemetryProperties common) { headerObject = new JSONObj(JSONObj.ObjectType.OBJECT); eventList = new System.Collections.Generic.List <JSONObj>(); foreach (var Prop in common) { headerObject.AddField(Prop.Key, Prop.Value); } }
public static JSONObj Create(long val) { JSONObj obj = Create(); obj.type = ObjectType.NUMBER; obj.n = val; obj.useInt = true; obj.i = val; return(obj); }
async Task <JSONObj> GetResults(string url) { JSONObj result = null; HttpResponseMessage response = await client.GetAsync(url).ConfigureAwait(false); if (response.IsSuccessStatusCode) { result = await response.Content.ReadAsAsync <JSONObj>(); } return(result); }
// Debug utility function for outputting telemetry to a string for printing public static string DumpJson(TelemetryProperties properties) { JSONObj jObject = new JSONObj(JSONObj.ObjectType.OBJECT); foreach (var Prop in properties) { jObject.AddField(Prop.Key, Prop.Value); } return(jObject.Print()); }
public void AddTelemetry(TelemetryBuilder inEvent) { JSONObj eventObject = new JSONObj(JSONObj.ObjectType.OBJECT); foreach (var Prop in inEvent) { eventObject.AddField(Prop.Key, Prop.Value); } eventList.Add(eventObject); }
public void Absorb(JSONObj obj) { list.AddRange(obj.list); keys.AddRange(obj.keys); str = obj.str; n = obj.n; useInt = obj.useInt; i = obj.i; b = obj.b; type = obj.type; }
public QueryEvent Parse(JSONObj jObj) { Debug.Assert(jObj.IsObject); QueryEvent ev = new QueryEvent(); for (int i = 0; i < jObj.keys.Count; i++) { ev.Attributes.Add(jObj.keys[i], jObj.list[i]); } return(ev); }
// Overload for BETWEEN query nodes public QueryNode(QueryNodeType type, string column, QueryOp op, JSONObj value1, JSONObj value2) { // Between and In operators are the only ones that know to look at the values array Debug.Assert(op == QueryOp.Btwn || op == QueryOp.In); this.Type = type; this.Column = column; this.Operator = op; this.Children = new QueryNodeList(); this.Value = JSONObj.obj; Value.Add(value1); Value.Add(value2); }
public static JSONObj Create(Vector3 val) { JSONObj obj = Create(ObjectType.OBJECT); JSONObj x = Create(val.x); JSONObj y = Create(val.y); JSONObj z = Create(val.z); obj.AddField("x", x); obj.AddField("y", y); obj.AddField("z", z); return(obj); }
async Task RunAsync(string url) { client.BaseAddress = new Uri(url); try { JSONObj result = await GetResults(url).ConfigureAwait(false); _distance = result.rows[0].Elements[0].Distance.Text; } catch (Exception e) { Console.WriteLine(e.Message); } }