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));
    }
相关推荐
上海合宙LuatOS5 天前
LuatOS核心库API——【json 】json 生成和解析库
java·前端·网络·单片机·嵌入式硬件·物联网·json
敲代码的柯基5 天前
一篇文章理解tsconfig.json和vue.config.js
javascript·vue.js·json
万物得其道者成5 天前
前端大整数精度丢失:一次踩坑后的实战解决方案(`json-bigint`)
前端·json
Ai runner6 天前
Show call stack in perfetto from json input
java·前端·json
ID_180079054736 天前
淘宝商品详情API请求的全场景,带json数据参考
服务器·数据库·json
恒云客6 天前
python uv debug launch.json
数据库·python·json
wanderist.7 天前
从 TCP 到 JSON:一次 FastAPI + LLM 生产环境 “Unexpected end of JSON input” 的底层剖析
tcp/ip·json·fastapi
享誉霸王7 天前
15、告别混乱!Vue3复杂项目的规范搭建与基础库封装实战
前端·javascript·vue.js·前端框架·json·firefox·html5
今心上8 天前
关于json的理解测试!!
开发语言·json
强子感冒了9 天前
JSON和XML学习笔记
xml·学习·json