public static OSD DeserializeJson(JsonData json) { switch (json.GetJsonType()) { case JsonType.Boolean: return OSD.FromBoolean((bool)json); case JsonType.Int: return OSD.FromInteger((int)json); case JsonType.Long: return OSD.FromLong((long)json); case JsonType.Double: return OSD.FromReal((double)json); case JsonType.String: string str = (string)json; if (String.IsNullOrEmpty(str)) return new OSD(); else return OSD.FromString(str); case JsonType.Array: OSDArray array = new OSDArray(json.Count); for (int i = 0; i < json.Count; i++) array.Add(DeserializeJson(json[i])); return array; case JsonType.Object: OSDMap map = new OSDMap(json.Count); foreach (KeyValuePair<string, JsonData> kvp in json) map.Add(kvp.Key, DeserializeJson(kvp.Value)); return map; case JsonType.None: default: return new OSD(); } }
public static OSD DeserializeJson(JsonData json) { switch (json.GetJsonType()) { case JsonType.Boolean: return OSD.FromBoolean((bool)json); case JsonType.Int: return OSD.FromInteger((int)json); case JsonType.Long: return OSD.FromLong((long)json); case JsonType.Double: return OSD.FromReal((double)json); case JsonType.String: string str = (string)json; if (String.IsNullOrEmpty(str)) return new OSD(); else return OSD.FromString(str); case JsonType.Array: OSDArray array = new OSDArray(json.Count); for (int i = 0; i < json.Count; i++) array.Add(DeserializeJson(json[i])); return array; case JsonType.Object: OSDMap map = new OSDMap(json.Count); IDictionaryEnumerator e = ((IOrderedDictionary)json).GetEnumerator(); while (e.MoveNext()) map.Add((string)e.Key, DeserializeJson((JsonData)e.Value)); return map; case JsonType.None: default: return new OSD(); } }
static int GetJsonType(IntPtr L) { try { ToLua.CheckArgsCount(L, 1); LitJson.JsonData obj = (LitJson.JsonData)ToLua.CheckObject(L, 1, typeof(LitJson.JsonData)); LitJson.JsonType o = obj.GetJsonType(); ToLua.Push(L, o); return(1); } catch (Exception e) { return(LuaDLL.toluaL_exception(L, e)); } }
private void PredicatePreloadingAssets(LitJson.JsonData jsonNode, Dictionary <string, int> preload) { if (jsonNode == null || jsonNode.GetJsonType() == JsonType.None) { return; } if (jsonNode.ContainsKey(SerializationConst.components)) { var componentsJson = jsonNode[SerializationConst.components]; int componentsCount = componentsJson.Count; for (int i = 0; i < componentsCount; i++) { var componentJson = componentsJson[i]; if ((string)componentJson[SerializationConst.type] == typeof(Part).Name) { if (!componentJson.ContainsKey(SerializationConst.userDatas)) { throw new Exception(componentJson.ToJson()); } if (!componentJson[SerializationConst.userDatas].ContainsKey(SerializationConst.address)) { throw new Exception(componentJson.ToJson()); } string partAddress = (string)componentJson[SerializationConst.userDatas][SerializationConst.address]; preload[partAddress] = preload.FindOrAdd(partAddress) + 1; } } } if (jsonNode.ContainsKey(SerializationConst.children)) { var childrenJson = jsonNode[SerializationConst.children]; int childrenCount = childrenJson.Count; for (int i = 0; i < childrenCount; i++) { var childJson = childrenJson[i]; PredicatePreloadingAssets(childJson, preload); } } }
public static bool SetObjectValue(object instance, string path, string json) { JsonData jsonData = null; if (json == null || json == "null") { // 删除操作,使用"null",而不是"",""代表空字符串 // 例如 //{ // "path": "activity.8", // "value": "null" //} // 保持jsonData = null即可 } else { try { jsonData = ToObject(json); } catch (Exception) { // 某些情况解析不了会抛异常 jsonData = new JsonData(json); } if (jsonData.GetJsonType() == JsonType.None) { // string型的json data会进行类型强转 jsonData = new JsonData(json); } } bool ret = SetObjectValue(instance, path, jsonData); return(ret); }
public static OSD DeserializeJson(JsonData json) { switch (json.GetJsonType()) { case JsonType.Boolean: return OSD.FromBoolean((bool)json); case JsonType.Int: return OSD.FromInteger((int)json); case JsonType.Long: return OSD.FromLong((long)json); case JsonType.Double: return OSD.FromReal((double)json); case JsonType.String: string str = (string)json; if (String.IsNullOrEmpty(str)) { return new OSD(); } else { switch (str[0]) { case 'd': if (str.StartsWith("date::")) { DateTime dt; if (DateTime.TryParse(str.Substring(6), out dt)) return OSD.FromDate(dt); } break; case 'u': if (str.StartsWith("uuid::")) { UUID id; if (UUID.TryParse(str.Substring(6), out id)) return OSD.FromUUID(id); } else if (str.StartsWith("uri::")) { try { Uri uri = new Uri(str.Substring(5)); return OSD.FromUri(uri); } catch (UriFormatException) { } } break; case 'b': if (str.StartsWith("b64::")) { try { byte[] data = Convert.FromBase64String(str.Substring(5)); return OSD.FromBinary(data); } catch (FormatException) { } } break; } return OSD.FromString((string)json); } case JsonType.Array: OSDArray array = new OSDArray(json.Count); for (int i = 0; i < json.Count; i++) array.Add(DeserializeJson(json[i])); return array; case JsonType.Object: OSDMap map = new OSDMap(json.Count); foreach (KeyValuePair<string, JsonData> kvp in json) map.Add(kvp.Key, DeserializeJson(kvp.Value)); return map; case JsonType.None: default: return new OSD(); } }
private JsonType GetJsonType(JsonData data) { if (data == null) { return JsonType.Object; } return data.GetJsonType(); }
List <PoseData> ReadPose(string text) //json 텍스트에서 포즈 읽어오기 { LitJson.JsonData jsonData = LitJson.JsonMapper.ToObject(text); List <PoseData> poseDatas = new List <PoseData>(); int personIndex = -1; int kpIndex = -1; string debugText = ""; List <string> debugTextList = new List <string>(); //Version //print(string.Format("version : {0}", poseData["version"])); //Keypoints foreach (LitJson.JsonData people in (jsonData["people"] as IList)) { personIndex++; PoseData personPoseData = new PoseData(); //foreach (LitJson.JsonData kp in (people["pose_keypoints_2d"] as IList)) {; } for (int i = 0; i < (people["pose_keypoints_2d"] as IList).Count; i++) { LitJson.JsonData kp = (LitJson.JsonData)(people["pose_keypoints_2d"] as IList)[i]; kpIndex++; //Make debug text if (logEnabled) { debugTextList.Add(string.Concat(debugText, string.Format( "[person <b>{0}</b> / kp <b>{1}</b>] : <b>{2}</b>\n", personIndex, kpIndex, kp))); //debugText = string.Concat( debugText , string.Format( // "[person <b>{0}</b> / kp <b>{1}</b>] : <b>{2}</b>\n", // personIndex, kpIndex, kp)); } // Add poseData if (kpIndex % 3 == 0) { //print(kp.GetJsonType().ToString()); if (kp.GetJsonType() == JsonType.Double) { personPoseData.positions[kpIndex / 3].x = (float)(double)kp; } else if (kp.GetJsonType() == JsonType.Int) { personPoseData.positions[kpIndex / 3].x = (int)kp; } //print("x " + personPoseData.positions[personIndex / 3].x); //personPoseData.positions[personIndex / 3].x = (float)(double)kp; } if (kpIndex % 3 == 1) { if (kp.GetJsonType() == JsonType.Double) { personPoseData.positions[kpIndex / 3].y = (float)(double)kp; } else if (kp.GetJsonType() == JsonType.Int) { personPoseData.positions[kpIndex / 3].y = (int)kp; } //print("y " + personPoseData.positions[personIndex / 3].y); //personPoseData.positions[personIndex / 3].y = (float)(double)kp; } if (kpIndex % 3 == 2) { if (kp.GetJsonType() == JsonType.Double) { personPoseData.confidences[kpIndex / 3] = (float)(double)kp; } else if (kp.GetJsonType() == JsonType.Int) { personPoseData.confidences[kpIndex / 3] = (int)kp; } //print("conf " + personPoseData.confidences[personIndex / 3]); //personPoseData.confidences[personIndex / 3] = (float)(double)kp; } } kpIndex = -1; poseDatas.Add(personPoseData); } //Print debug log if (logEnabled) { debugText = string.Concat(debugTextList.ToArray()); print(debugText); } return(poseDatas); //print(string.Format("kp : {0}", poseData["people"][0]["pose_keypoints_2d"][0])); }