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));
    }
相关推荐
loopfde成序2 天前
Web-RAG 检索可见度评估体系与站点 JSON-LD 及 llms.txt 自动化核验实践
前端·自动化·json
麻瓜code7 天前
流式返回的工具参数是一段一段来的,怎么拼成一个 JSON
json
鲸渔9 天前
【AI Agent系列课程13-Python 基础13】JSON 读写:结构化数据交换基础
开发语言·python·json·ai编程
aiotto资源分享11 天前
Python 写 JSON 文件,程序中途退出会留下什么?
java·python·json·jsondecodeerror
一起学安全技术12 天前
拆大模型 10|结构化输出:让模型返回数据,而不是一段话
人工智能·语言模型·json
用户2986985301412 天前
在 Python 中把 Word 文档转换为 JSON 的三种实现方式
python·json·api
FRing0314 天前
vue2干货总结10(json-server、vant-ui、postcss插件、axios二次封装、图形验证码、toast轻提示)
开发语言·前端·vue.js·ui·json·vue2·postcss
用户2986985301414 天前
使用 Python 将 JSON 转换为 Word 文档的实践指南
python·json·api
九英里路15 天前
protobuf快速上手
网络·c++·中间件·json·谷歌·序列化·protobuf
wuyk55516 天前
Spider-第09讲-三格式落盘CSV-Excel-JSON
爬虫·python·json·excel