byte[] bytes = { 0x01, 0x02, 0x03 }
string binaryString = System.BitConverter.ToString(bytes)
Console.WriteLine(binaryString)// 输出 01-02-03
方法一 直接传结构体与保持文件名字
public void WriteJson(object ob, string jsonName)
{
string json = LitJson.JsonMapper.ToJson(ob)
byte[] bytes = System.Text.Encoding.UTF8.GetBytes(json)
string filePath = Application.dataPath + "/Resources/" + jsonName + ".json"
using (System.IO.FileStream stream = new System.IO.FileStream(filePath, System.IO.FileMode.Create))
{
stream.Write(bytes, 0, bytes.Length)
}
UnityEditor.AssetDatabase.Refresh()//属性掘薯困Asset,生成完成后立刻可以看到文件
}
方法二 jsonwriter 半编译写法
void CreateJson()
{
string path = Application.dataPath + "/Resources/Jsons/" + objBase.transform.name + ".json"
FileInfo fileInfo = new FileInfo(path)
StreamWriter sw = fileInfo.CreateText()
StringBuilder sb = new StringBuilder()
JsonWriter jsonwriter = new JsonWriter(sb)
jsonwriter.WriteObjectStart()//1
for (int i = 0i <numbers.Counti++)
{
jsonwriter.WritePropertyName("Number" + (i + 1))
jsonwriter.WriteObjectStart()//1-1
type = new List<Transform>()
foreach (Transform child in numbers[i].transform)
type.Add(child)
jsonwriter.WritePropertyName("TypeCount")jsonwriter.Write(type.Count)
手举 for (int j = 0j <type.Countj++)
{
jsonwriter.WritePropertyName("Type"判念 + (j + 1))
jsonwriter.WriteObjectStart()//1-1-1
pos = new List<Transform>()
foreach (Transform child in type[j].transform)
pos.Add(child)
jsonwriter.WritePropertyName("Size")jsonwriter.Write(pos[0].transform.localScale.x.ToString())
jsonwriter.WritePropertyName("Pos")
jsonwriter.WriteArrayStart()
for (int k = 0k <pos.Countk++)
{
jsonwriter.Write("(" + pos[k].transform.localPosition.x + "," + pos[k].transform.localPosition.y + ")")
}
jsonwriter.WriteArrayEnd()
jsonwriter.WriteObjectEnd()//1-1-1
}
jsonwriter.WriteObjectEnd()//1-1
}
jsonwriter.WriteObjectEnd()//1
sw.WriteLine(sb.ToString())
sw.Close()
AssetDatabase.Refresh()
}
Json 里面的数据是double 类型,使用float 会出问题
double.Parse float .Parse 不一样
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)