private static void MenuItem_Normalize() { string t_jsonstring_raw = BlueBack.AssetLib.Editor.LoadTextWithUrl.LoadNoBomUtf8("https://api.github.com/repos/bluebackblue/AssetLib/tags", null); UnityEngine.Debug.Log(t_jsonstring_raw); //空白、タブ、改行を省く。 string t_jsonstring_normalize = BlueBack.JsonItem.Normalize.Convert(t_jsonstring_raw); UnityEngine.Debug.Log(t_jsonstring_normalize); //整形。 string t_jsonstring_pretty = BlueBack.JsonItem.Pretty.Convert(t_jsonstring_normalize, "\t"); UnityEngine.Debug.Log(t_jsonstring_pretty); BlueBack.JsonItem.JsonItem t_jsonitem = new BlueBack.JsonItem.JsonItem(t_jsonstring_normalize); int ii_max = t_jsonitem.GetListMax(); for (int ii = 0; ii < ii_max; ii++) { UnityEngine.Debug.Log(t_jsonitem.GetItem(ii).GetItem("name").GetStringData()); } }
//<<CS_BLOCK_END>> /** Update */ public void Update() //<<CS_BLOCK_START>> { Item t_from_item = new Item() { x = 10, yy = 11, zzz = 123.4f, }; //JsonItemにコンバート。 BlueBack.JsonItem.JsonItem t_jsonitem = BlueBack.JsonItem.Convert.ObjectToJsonItem(t_from_item); //JSON文字列にコンバート。 string t_jsonstring = t_jsonitem.ConvertToJsonString(); UnityEngine.Debug.Log("ConvertToJsonString : " + t_jsonstring); //オブジェクトにコンバート。 Item t_to_item = t_jsonitem.ConvertToObject <Item>(); UnityEngine.Debug.Log("ConvertToObject : x = " + t_to_item.x.ToString()); UnityEngine.Debug.Log("ConvertToObject : yy = " + t_to_item.yy.ToString()); UnityEngine.Debug.Log("ConvertToObject : zzz = " + t_to_item.zzz.ToString()); //JsonItemから直接取り出す。 t_jsonitem = new BlueBack.JsonItem.JsonItem(t_jsonstring); UnityEngine.Debug.Log("JsonItem : x = " + t_jsonitem.GetItem("x").CastToInt32().ToString()); UnityEngine.Debug.Log("JsonItem : yy = " + t_jsonitem.GetItem("yy").GetBoolData().ToString()); UnityEngine.Debug.Log("JsonItem : zzz = " + t_jsonitem.GetItem("zzz").CastToSingle().ToString()); }
private static void MenuItem_Test() { Item t_from_item = new Item() { x = 100, yy = true, zzz = 99.99f, e1 = E.A, e2 = E.B, }; //JsonItemにコンバート。 BlueBack.JsonItem.JsonItem t_jsonitem = BlueBack.JsonItem.Convert.ObjectToJsonItem(t_from_item); //JSON文字列にコンバート。 string t_jsonstring = t_jsonitem.ConvertToJsonString(); UnityEngine.Debug.Log("ConvertToJsonString : " + t_jsonstring); //オブジェクトにコンバート。 Item t_to_item = BlueBack.JsonItem.Convert.JsonItemToObject <Item>(t_jsonitem); UnityEngine.Debug.Log("ConvertToObject : x = " + t_to_item.x.ToString()); UnityEngine.Debug.Log("ConvertToObject : yy = " + t_to_item.yy.ToString()); UnityEngine.Debug.Log("ConvertToObject : zzz = " + t_to_item.zzz.ToString()); UnityEngine.Debug.Log("ConvertToObject : e1 = " + t_to_item.e1.ToString()); UnityEngine.Debug.Log("ConvertToObject : e2 = " + t_to_item.e2.ToString()); //JsonItemから直接取り出す。 t_jsonitem = new BlueBack.JsonItem.JsonItem(t_jsonstring); UnityEngine.Debug.Log("JsonItem : x = " + t_jsonitem.GetItem("x").CastToInt32().ToString()); UnityEngine.Debug.Log("JsonItem : yy = " + t_jsonitem.GetItem("yy").GetBoolData().ToString()); UnityEngine.Debug.Log("JsonItem : zzz = " + t_jsonitem.GetItem("zzz").CastToSingle().ToString()); UnityEngine.Debug.Log("JsonItem : e1 = " + t_jsonitem.GetItem("e1").GetStringData()); UnityEngine.Debug.Log("JsonItem : e2 = " + t_jsonitem.GetItem("e2").CastToInt32().ToString()); E t_e2 = BlueBack.JsonItem.Convert.JsonItemToObject <E>(t_jsonitem.GetItem("e2")); UnityEngine.Debug.Log("Direct : e2 = " + t_e2.ToString()); }
/** Get */ public static System.Type Get(BlueBack.JsonItem.JsonItem a_jsonitem) { #pragma warning disable 0162 switch (a_jsonitem.GetValueType()) { case ValueType.Null: { //値型が不明なので値型はSystem.Objectにする。 return(typeof(System.Object)); } break; case ValueType.AssociativeArray: { //値型が不明なので値型はSystem.Objectにする。 return(typeof(System.Collections.Generic.Dictionary <string, System.Object>)); } break; case ValueType.IndexArray: { //値型が不明なので値型はSystem.Objectにする。 return(typeof(System.Collections.Generic.List <System.Object>)); } break; case ValueType.StringData: { return(typeof(System.String)); } break; case ValueType.SignedNumber: { return(JsonItem.GetSignedNumberType()); } break; case ValueType.UnsignedNumber: { return(JsonItem.GetUnsignedNumberType()); } break; case ValueType.FloatingNumber: { return(JsonItem.GetFloatingNumberType()); } break; case ValueType.BoolData: { return(typeof(System.Boolean)); } break; case ValueType.DecimalNumber: { return(typeof(System.Decimal)); } break; case ValueType.BinaryData: { return(typeof(System.Collections.Generic.List <byte>)); } break; default: { #if (DEF_BLUEBACK_JSONITEM_ASSERT) DebugTool.Assert(false); #endif return(null); } break; } #pragma warning restore }
/** Draw */ public void Draw(int a_nest, string a_name, string a_address, BlueBack.JsonItem.JsonItem a_jsonitem) { if (a_jsonitem == null) { UnityEditor.EditorGUILayout.LabelField("null"); } else { switch (a_jsonitem.value.valuetype) { case BlueBack.JsonItem.ValueType.Null: { if (a_name != null) { UnityEditor.EditorGUILayout.LabelField(a_name + " : Null"); } else { UnityEditor.EditorGUILayout.LabelField("Null"); } } break; case BlueBack.JsonItem.ValueType.IndexArray: { System.Collections.Generic.List <BlueBack.JsonItem.JsonItem> t_list = a_jsonitem.GetIndexArray(); string t_name; if (a_name != null) { t_name = a_name + " : IndexArray(" + t_list.Count.ToString() + ")"; } else { t_name = "IndexArray(" + t_list.Count.ToString() + ")"; } if (this.SetExpanded(a_address, UnityEditor.EditorGUILayout.Foldout(this.GetExpanded(a_address), t_name)) == true) { UnityEditor.EditorGUI.indentLevel++; for (int ii = 0; ii < t_list.Count; ii++) { this.Draw(a_nest + 1, null, a_address + "." + ii.ToString(), t_list[ii]); } UnityEditor.EditorGUI.indentLevel--; } } break; case BlueBack.JsonItem.ValueType.AssociativeArray: { System.Collections.Generic.Dictionary <string, BlueBack.JsonItem.JsonItem> t_list = a_jsonitem.GetAssociativeArray(); string t_name; if (a_name != null) { t_name = a_name + " : AssociativeArray(" + t_list.Count.ToString() + ")"; } else { t_name = "AssociativeArray(" + t_list.Count.ToString() + ")"; } if (this.SetExpanded(a_address, UnityEditor.EditorGUILayout.Foldout(this.GetExpanded(a_address), t_name)) == true) { UnityEditor.EditorGUI.indentLevel++; foreach (System.Collections.Generic.KeyValuePair <string, BlueBack.JsonItem.JsonItem> t_pair in t_list) { this.Draw(a_nest + 1, t_pair.Key, a_address + "." + t_pair.Key, t_pair.Value); } UnityEditor.EditorGUI.indentLevel--; } } break; case BlueBack.JsonItem.ValueType.BinaryData: { System.Collections.Generic.List <byte> t_list = a_jsonitem.GetBinaryData(); string t_name; if (a_name != null) { t_name = a_name + " : BinaryData(" + t_list.Count.ToString() + ")"; } else { t_name = "BinaryData(" + t_list.Count.ToString() + ")"; } if (this.SetExpanded(a_address, UnityEditor.EditorGUILayout.Foldout(this.GetExpanded(a_address), t_name)) == true) { UnityEditor.EditorGUI.indentLevel++; System.Text.StringBuilder t_stringbuilder = new System.Text.StringBuilder(32); int t_index = 0; while (t_index < t_list.Count) { t_stringbuilder.Clear(); for (int ii = t_index; ((ii < t_list.Count) && (ii < t_index + 16)); ii++) { t_stringbuilder.Append(t_list[ii].ToString("X2")); t_stringbuilder.Append(" "); } UnityEditor.EditorGUILayout.LabelField(t_stringbuilder.ToString()); t_index += 16; } UnityEditor.EditorGUI.indentLevel--; } } break; case BlueBack.JsonItem.ValueType.StringData: { if (a_name != null) { UnityEditor.EditorGUILayout.LabelField(a_name + " : StringData", a_jsonitem.GetStringData()); } else { UnityEditor.EditorGUILayout.LabelField("StringData", a_jsonitem.GetStringData()); } } break; case BlueBack.JsonItem.ValueType.SignedNumber: { if (a_name != null) { UnityEditor.EditorGUILayout.LabelField(a_name + " : SignedNumber", a_jsonitem.GetSignedNumber().ToString()); } else { UnityEditor.EditorGUILayout.LabelField("SignedNumber", a_jsonitem.GetSignedNumber().ToString()); } } break; case BlueBack.JsonItem.ValueType.UnsignedNumber: { if (a_name != null) { UnityEditor.EditorGUILayout.LabelField(a_name + " : UnsignedNumber", a_jsonitem.GetUnsignedNumber().ToString()); } else { UnityEditor.EditorGUILayout.LabelField("UnsignedNumber", a_jsonitem.GetUnsignedNumber().ToString()); } } break; case BlueBack.JsonItem.ValueType.FloatingNumber: { if (a_name != null) { UnityEditor.EditorGUILayout.LabelField(a_name + " : FloatingNumber", a_jsonitem.GetFloatingNumber().ToString()); } else { UnityEditor.EditorGUILayout.LabelField("FloatingNumber", a_jsonitem.GetFloatingNumber().ToString()); } } break; case BlueBack.JsonItem.ValueType.BoolData: { if (a_name != null) { UnityEditor.EditorGUILayout.LabelField(a_name + " : BoolData", a_jsonitem.GetBoolData().ToString()); } else { UnityEditor.EditorGUILayout.LabelField("BoolData", a_jsonitem.GetBoolData().ToString()); } } break; case BlueBack.JsonItem.ValueType.DecimalNumber: { if (a_name != null) { UnityEditor.EditorGUILayout.LabelField(a_name + " : DecimalNumber", a_jsonitem.GetDecimalNumber().ToString()); } else { UnityEditor.EditorGUILayout.LabelField("DecimalNumber", a_jsonitem.GetDecimalNumber().ToString()); } } break; } } }