Json的操作

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));
    }
相关推荐
烂蜻蜓1 小时前
Pandas入门教程(六):数据读写详解——CSV、JSON、Pickle 与格式选型
json·pandas
etafort4 小时前
js格式化json树结构
json
喵喵虫1 天前
汉字笔顺笔画元数据导出 JSON
小程序·json·元数据·汉字·笔顺·笔画
熊猫钓鱼>_>1 天前
Kotlin Multiplatform for OpenHarmony 实战:kotlinx-serialization JSON 适配
开发语言·华为·kotlin·华为云·json·harmonyos·code
雪芽蓝域zzs2 天前
json数据转化成interface属性
前端·javascript·json
ha_lydms2 天前
Json Functions(JSON 函数)
大数据·hadoop·spark·json·数据处理·dataworks·maxcompute
BD_Marathon2 天前
JSONLoader加载JSON文件
json
积流成海2 天前
JSON 格式化:语法校验与错误定位实践
json·状态模式·盘子工具站
JavaPub-rodert3 天前
Docker 日志为什么能把磁盘写爆?讲透 json-file、local、journald、日志轮转与 docker logs
docker·eureka·json