internal string GetString(string Name) { Newtonsoft.Json.Linq.JToken value; if (_ParsedData.TryGetValue(Name, out value)) { return(value.ToString()); } else { return(""); } }
private string getValue(Newtonsoft.Json.Linq.JObject obj, string propertyName) { Newtonsoft.Json.Linq.JToken value = null; if (obj.TryGetValue(propertyName, StringComparison.OrdinalIgnoreCase, out value) == true) { return(value?.ToString()); } return(null); }
/* * public GameState Added * { * get * { * if (added == null) * added = new GameState(GetNode("added")); * * return added; * } * } */ private String GetNode(string name) { Newtonsoft.Json.Linq.JToken value; if (_ParsedData.TryGetValue(name, out value)) { return(value.ToString()); } else { return(""); } }
public override void UpdateEditorValue() { try { Newtonsoft.Json.Linq.JObject data = Newtonsoft.Json.JsonConvert.DeserializeObject <Newtonsoft.Json.Linq.JObject>(JsonValue); if (data != null) { Newtonsoft.Json.Linq.JToken v; if (data.TryGetValue("blendMode", out v)) { m_subProperties["blendMode"] = v.ToString(Newtonsoft.Json.Formatting.None); m_blendModeEditor.UpdateEditorValue(); } if (data.TryGetValue("shader", out v)) { m_subProperties["shader"] = v.ToString(Newtonsoft.Json.Formatting.None); m_shaderAssetEditor.UpdateEditorValue(); } } } catch { } }
public override void UpdateEditorValue() { try { Newtonsoft.Json.Linq.JObject data = Newtonsoft.Json.JsonConvert.DeserializeObject <Newtonsoft.Json.Linq.JObject>(JsonValue); if (data != null) { Newtonsoft.Json.Linq.JToken v; if (data.TryGetValue("id", out v)) { m_subProperties["id"] = v.ToString(Newtonsoft.Json.Formatting.None); m_idEditor.UpdateEditorValue(); } foreach (var metaEditor in m_metaEditors) { if (data.TryGetValue(metaEditor.Key, out v)) { m_subProperties[metaEditor.Key] = v.ToString(Newtonsoft.Json.Formatting.None); metaEditor.Value.UpdateEditorValue(); } } foreach (var propEditor in m_propertyEditors) { if (data.TryGetValue(propEditor.Key, out v)) { m_subProperties[propEditor.Key] = v.ToString(Newtonsoft.Json.Formatting.None); propEditor.Value.UpdateEditorValue(); } } if (data.TryGetValue("tags", out v)) { m_subProperties["tags"] = v.ToString(Newtonsoft.Json.Formatting.None); m_tagsEditor.UpdateEditorValue(); } } } catch { } }
public string GetString(string Name) { Newtonsoft.Json.Linq.JToken value; if (_ParsedData.TryGetValue(Name, StringComparison.OrdinalIgnoreCase, out value)) { return(value.ToString()); } else { return(""); } }
/// <summary> /// 执行业务方法 /// </summary> /// <param name="typeName">业务类型</param> /// <param name="fucName">方法名称</param> /// <param name="JObject">参数</param> /// <returns></returns> string Invoke(string typeName, string fucName, Newtonsoft.Json.Linq.JObject jObject) { var type = Type.GetType(string.Format("Water.Bussiness.{0},Water.Bussiness", typeName)); var fuc = type.GetMethod(fucName); object[] paras = null; var fucParas = fuc.GetParameters(); if (fucParas != null && fucParas.Length > 0 && jObject != null) { paras = new object[fucParas.Length]; for (int i = 0; i < fucParas.Length; i++) { Newtonsoft.Json.Linq.JToken paraValue; if (jObject.TryGetValue(fucParas[i].Name, out paraValue)) { paras[i] = paraValue.ToObject(fucParas[i].ParameterType); } } } string result = string.Empty; var instance = Activator.CreateInstance(type); if (fuc.ReturnType != typeof(void)) { result = Newtonsoft.Json.JsonConvert.SerializeObject(fuc.Invoke(instance, paras)); } else { result = Newtonsoft.Json.JsonConvert.SerializeObject(new StatusResult() { Status = Status.Success }); } return(result); }
public string[] getLatLng(string stress) { Thread.Sleep(1000); Scaler.Http http = new Scaler.Http(); string url = "http://apis.map.qq.com/jsapi?qt=geoc&addr=" + Scaler.Common.StrEncode(stress) + "&output=jsonp&pf=jsapi&ref=jsapi&cb=qq.maps._svcb3.geocoder0"; string content = http.GetHTML_WithEncode(url, "", "", "", "GET", Encoding.UTF8, Encoding.Default); int l = content.IndexOf("("); if (l > -1) { content = content.Substring(l + 1); } if (content.EndsWith(")")) { content = content.Remove(content.Length - 1, 1); } try { Newtonsoft.Json.Linq.JObject obj = Newtonsoft.Json.Linq.JObject.Parse(content); Newtonsoft.Json.Linq.JToken objValue; if (obj.TryGetValue("status", out objValue)) { return(null); } string lng = obj["detail"]["pointx"].ToString(); string lat = obj["detail"]["pointy"].ToString(); return(new string[] { lat, lng }); } catch { return(null); } }
static StackObject *TryGetValue_1(ILIntepreter __intp, StackObject *__esp, IList <object> __mStack, CLRMethod __method, bool isNewObj) { ILRuntime.Runtime.Enviorment.AppDomain __domain = __intp.AppDomain; StackObject *ptr_of_this_method; StackObject *__ret = ILIntepreter.Minus(__esp, 3); ptr_of_this_method = ILIntepreter.Minus(__esp, 1); Newtonsoft.Json.Linq.JToken @value = (Newtonsoft.Json.Linq.JToken) typeof(Newtonsoft.Json.Linq.JToken).CheckCLRTypes(__intp.RetriveObject(ptr_of_this_method, __mStack), (CLR.Utils.Extensions.TypeFlags) 0); ptr_of_this_method = ILIntepreter.Minus(__esp, 2); System.String @propertyName = (System.String) typeof(System.String).CheckCLRTypes(StackObject.ToObject(ptr_of_this_method, __domain, __mStack), (CLR.Utils.Extensions.TypeFlags) 0); ptr_of_this_method = ILIntepreter.Minus(__esp, 3); Newtonsoft.Json.Linq.JObject instance_of_this_method = (Newtonsoft.Json.Linq.JObject) typeof(Newtonsoft.Json.Linq.JObject).CheckCLRTypes(StackObject.ToObject(ptr_of_this_method, __domain, __mStack), (CLR.Utils.Extensions.TypeFlags) 0); var result_of_this_method = instance_of_this_method.TryGetValue(@propertyName, out @value); ptr_of_this_method = ILIntepreter.Minus(__esp, 1); switch (ptr_of_this_method->ObjectType) { case ObjectTypes.StackObjectReference: { var ___dst = ILIntepreter.ResolveReference(ptr_of_this_method); object ___obj = @value; if (___dst->ObjectType >= ObjectTypes.Object) { if (___obj is CrossBindingAdaptorType) { ___obj = ((CrossBindingAdaptorType)___obj).ILInstance; } __mStack[___dst->Value] = ___obj; } else { ILIntepreter.UnboxObject(___dst, ___obj, __mStack, __domain); } } break; case ObjectTypes.FieldReference: { var ___obj = __mStack[ptr_of_this_method->Value]; if (___obj is ILTypeInstance) { ((ILTypeInstance)___obj)[ptr_of_this_method->ValueLow] = @value; } else { var ___type = __domain.GetType(___obj.GetType()) as CLRType; ___type.SetFieldValue(ptr_of_this_method->ValueLow, ref ___obj, @value); } } break; case ObjectTypes.StaticFieldReference: { var ___type = __domain.GetType(ptr_of_this_method->Value); if (___type is ILType) { ((ILType)___type).StaticInstance[ptr_of_this_method->ValueLow] = @value; } else { ((CLRType)___type).SetStaticFieldValue(ptr_of_this_method->ValueLow, @value); } } break; case ObjectTypes.ArrayReference: { var instance_of_arrayReference = __mStack[ptr_of_this_method->Value] as Newtonsoft.Json.Linq.JToken[]; instance_of_arrayReference[ptr_of_this_method->ValueLow] = @value; } break; } __intp.Free(ptr_of_this_method); ptr_of_this_method = ILIntepreter.Minus(__esp, 2); __intp.Free(ptr_of_this_method); ptr_of_this_method = ILIntepreter.Minus(__esp, 3); __intp.Free(ptr_of_this_method); __ret->ObjectType = ObjectTypes.Integer; __ret->Value = result_of_this_method ? 1 : 0; return(__ret + 1); }
void RawJsonCallback(string json) { Console.WriteLine(json); Newtonsoft.Json.Linq.JObject statusjson = new Newtonsoft.Json.Linq.JObject(); Newtonsoft.Json.Linq.JToken jtoken; statusjson = Newtonsoft.Json.Linq.JObject.Parse(json); if (statusjson.TryGetValue("text", out jtoken)) { label1.Text += "\n" + (string)statusjson["user"]["name"] + "「" + (string)statusjson["text"] + "」"; } //label1.Text += "\n" + json; }
public static BDO JsonToBDO(BDOs owner, BDO parentBDO, string busino, string jsonData) { BDO bdo = new BDO(owner, parentBDO, busino, "1<>1", false, -1, -1, false); try { ArrayList arrayList = JsonConvert.DeserializeObject <ArrayList>(jsonData); foreach (var v in arrayList) { Newtonsoft.Json.Linq.JObject jobj = v as Newtonsoft.Json.Linq.JObject; string dataState = "0"; //0-unchange,1-add,2-modify,3-delete Newtonsoft.Json.Linq.JToken token; if (jobj.TryGetValue("dataState", out token)) { dataState = token.ToString(); } //if (dataState == "0") continue; DataRow nr = bdo.NewRow(); bdo.Rows.Add(nr); if (dataState == "2") { foreach (var vv in jobj) { if (!vv.Key.EndsWith("_old")) { continue; } string filedName = vv.Key.Substring(0, vv.Key.Length - 4); if (!bdo.Columns.Contains(filedName)) { continue; } if (vv.Value.GetType() == typeof(Newtonsoft.Json.Linq.JObject) || vv.Value.GetType() == typeof(Newtonsoft.Json.Linq.JArray)) { if (bdo.Columns[filedName].DataType != typeof(string)) { continue; } nr[filedName] = vv.Value.ToString(); } else { if (((Newtonsoft.Json.Linq.JValue)vv.Value).Value == null && !bdo.Columns[filedName].AllowDBNull) { continue; } if (((Newtonsoft.Json.Linq.JValue)vv.Value).Type == Newtonsoft.Json.Linq.JTokenType.Boolean) { nr[filedName] = (bool)((Newtonsoft.Json.Linq.JValue)vv.Value).Value ? 1 : 0; } else { nr[filedName] = ((Newtonsoft.Json.Linq.JValue)vv.Value).Value == null || ((Newtonsoft.Json.Linq.JValue)vv.Value).Value.Equals("") || ((Newtonsoft.Json.Linq.JValue)vv.Value).Value.Equals("null") ? DBNull.Value : vv.Value.ToObject(bdo.Columns[filedName].DataType); } } } nr.AcceptChanges(); } bool flg = true; foreach (var vv in jobj) { if (!bdo.Columns.Contains(vv.Key)) { continue; } if (vv.Key.EndsWith("_old")) { continue; } if (vv.Value.GetType() == typeof(Newtonsoft.Json.Linq.JObject)) { continue; } var vl = (Newtonsoft.Json.Linq.JValue)vv.Value; if ((vl.Value == null || vl.Value.ToString().ToUpper() == "NULL") && !bdo.Columns[vv.Key].AllowDBNull) { continue; } if (dataState == "1" && bdo.Columns[vv.Key].DataType == typeof(Guid)) { ((BRO)nr).OldID = vl.Value; continue; } if (!nr[vv.Key].Equals(vl.Value)) { flg = flg & false; } if (vl.Value == null || vl.Value.ToString().ToUpper() == "NULL") { nr[vv.Key] = DBNull.Value; } else if (vl.Type == Newtonsoft.Json.Linq.JTokenType.String && (bdo.Columns[vv.Key].DataType == typeof(Boolean) || bdo.Columns[vv.Key].DataType == typeof(Int32)) && (vl.Value.ToString().ToUpper() == "TRUE" || vl.Value.ToString().ToUpper() == "FALSE")) { nr[vv.Key] = vl.Value.ToString().ToUpper() == "TRUE" ? 1 : 0; } else if (vv.Value.Type == Newtonsoft.Json.Linq.JTokenType.Boolean) { nr[vv.Key] = (vv.Value.HasValues || vl.Value.ToString().ToUpper() == "TRUE") ? 1 : 0; } else { //if (!nr[vv.Key].Equals(vl.Value)) // flg = flg & false; object objValue = ((Newtonsoft.Json.Linq.JValue)vv.Value).Value; nr[vv.Key] = objValue == null || string.IsNullOrEmpty(objValue.ToString().Trim()) ? DBNull.Value : vv.Value.ToObject(bdo.Columns[vv.Key].DataType); } } if (dataState == "2" && flg) { nr.AcceptChanges(); } if (dataState == "3") { nr.AcceptChanges(); nr.Delete(); } else if (dataState == "0") { nr.AcceptChanges(); } } } catch (Exception ex) { if (ex.Message == "Input string was not in a correct format.") { throw new ApplicationException("数据类型转换错误, 请删除后再输入重试."); } else { throw ex; } } return(bdo); }
/// <summary> /// Handler for "grasshopper/solve-jsonobject" POST /// </summary> /// <param name="input"> /// JSON data generated in Rhino/Grasshopper for a given definition /// { /// "input": [ /// { /// "nickname": "CtxPt", /// "instanceGuid": "6a67a2dc-3fb9-49da-92fb-c11bec3323f9", /// "points": [ /// [4.67739437581401,-4.93724961891479,0] /// ] /// }, /// ... /// ], /// "definition": base64 encoded string representing a gh file /// } /// </param> /// <returns> /// JSON array /// [ /// { /// "instanceGuid": "fa19bc8b-5115-4b27-9d73-13eaaff3b8bc", /// "geometry": [ /// "base64 encoded Rhino.Runtime.CommonObject", /// ... /// ] /// }, /// ... /// ] /// </returns> public static Newtonsoft.Json.Linq.JArray Solve(Newtonsoft.Json.Linq.JObject input) { GH_Document definition = null; Newtonsoft.Json.Linq.JToken token; if (input.TryGetValue("definition", out token)) { string encoded = token.ToString(); byte[] byteArray = Convert.FromBase64String(encoded); var archive = new GH_IO.Serialization.GH_Archive(); if (archive.Deserialize_Binary(byteArray)) { definition = new GH_Document(); if (!archive.ExtractObject(definition, "Definition")) { definition.Dispose(); definition = null; } } } var rc = new Newtonsoft.Json.Linq.JArray(); if (definition != null && input.TryGetValue("input", out token)) { foreach (var obj in token) { var item = obj as Newtonsoft.Json.Linq.JObject; string instanceGuid = item.GetValue("instanceGuid").ToString(); var id = new System.Guid(instanceGuid); var component = definition.FindComponent(id); Newtonsoft.Json.Linq.JToken pointsToken; if (item.TryGetValue("points", out pointsToken)) { var method = component.GetType().GetMethod("SetSolvePoints"); List <Rhino.Geometry.Point3d> points = new List <Rhino.Geometry.Point3d>(); foreach (var pointToken in pointsToken) { var pts = pointToken as Newtonsoft.Json.Linq.JArray; double x = (double)pts[0]; double y = (double)pts[1]; double z = (double)pts[2]; points.Add(new Rhino.Geometry.Point3d(x, y, z)); } method.Invoke(component, new object[] { points }); } } definition.Enabled = true; definition.NewSolution(true, GH_SolutionMode.CommandLine); var components = definition.ActiveObjects(); var jobject = new Newtonsoft.Json.Linq.JObject(); for (int i = 0; i < components.Count; i++) { var method = components[i].GetType().GetMethod("GetCollectedGeometry"); if (method != null) { var geometryArray = method.Invoke(components[i], null) as Rhino.Geometry.GeometryBase[]; var id = components[i].InstanceGuid; jobject.Add("instanceId", id); var ja = new Newtonsoft.Json.Linq.JArray(); foreach (var geometry in geometryArray) { string s = Newtonsoft.Json.JsonConvert.SerializeObject(geometry, GeometryResolver.Settings); var g = Newtonsoft.Json.Linq.JObject.Parse(s); //var g = Newtonsoft.Json.Linq.JObject.FromObject(geometry); ja.Add(g); } jobject.Add("geometry", ja); rc.Add(jobject); } } } return(rc); }