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));
    }
相关推荐
q***49862 小时前
SpringCloud系列教程:微服务的未来 (五)枚举处理器、JSON处理器、分页插件实现
spring cloud·微服务·json
愤怒的山羊1 天前
jetcache List 缓存, json 序列化 泛型解析成了 JsonObject 处理
缓存·json·list
2***d8851 天前
使用 MySQL 从 JSON 字符串提取数据
mysql·oracle·json
TDengine (老段)2 天前
TDengine 转换函数 TO_JSON 用户手册
android·大数据·数据库·json·时序数据库·tdengine·涛思数据
wow_DG2 天前
【Python✨】VS Code 秒开 Python 类型检查:一招 mypy + settings.json 让你的 Bug 原地现形!
python·json·bug
会篮球的程序猿3 天前
html+canvas+thikphp 可视化工具拖拽、编辑生成JSON,渲染成海报图片 完全自定义,支持选择,文字背景色
前端·html·json
倚肆3 天前
Hutool-json 库完整指南
java·json
q***23924 天前
MySQL JSON数据类型全解析(JSON datatype and functions)
android·mysql·json
i_am_a_div_日积月累_5 天前
JSON数据转Excel
json·excel·css3
www_stdio6 天前
用 localStorage 打造本地待办清单:一个轻量级的前端实践
javascript·css·json