Json解析float报错,要使用double
第一种
csharp
void Start()
{
//Convert();
Convertddd();
}
public void Convertddd()
{
//LineDataDic d = new LineDataDic();
JsonData d = new JsonData();
for (int i = 0; i < 5; i++)
{
LineData convertData = new LineData();
convertData.targetIndex = i;
convertData.specialBox = i;
convertData.timer = 1.1f;
convertData.lineId = i;
//d.datas.Add(convertData);
d.Add(JsonMapper.ToObject(JsonMapper.ToJson(convertData)));
}
File.WriteAllText(Application.streamingAssetsPath+"/data.json",d.ToJson());
}
第二种
csharp
public class LineData
{
public int targetIndex;
public int specialBox;
public double timer;
public int lineId;
}
public class LineDataDic
{
public List<LineData> datas = new List<LineData>();
}
public class ConvertJson : MonoBehaviour
{
void Start()
{
//Convert();
Convertddd();
}
public void Convertddd()
{
LineDataDic d = new LineDataDic();
//JsonData d = new JsonData();
for (int i = 0; i < 5; i++)
{
LineData convertData = new LineData();
convertData.targetIndex = i;
convertData.specialBox = i;
convertData.timer = 1.1f;
convertData.lineId = i;
d.datas.Add(convertData);
}
File.WriteAllText(Application.streamingAssetsPath+"/data.json",JsonMapper.ToJson(d));
}