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));
    }
相关推荐
CSCN新手听安11 小时前
【linux】网络基础(三)TCP服务端网络版本计算器的优化,Json的使用,服务器守护进程化daemon,重谈OSI七层模型
linux·服务器·网络·c++·tcp/ip·json
bloglin9999912 小时前
Qwen3-32B报错Invalid json output:{“type“: “1“}For troubleshooting, visit
llm·json
Trouvaille ~12 小时前
【Linux】应用层协议设计实战(二):Jsoncpp序列化与完整实现
linux·运维·服务器·网络·c++·json·应用层
剩下了什么1 天前
MySQL JSON_SET() 函数
数据库·mysql·json
梦帮科技1 天前
Node.js配置生成器CLI工具开发实战
前端·人工智能·windows·前端框架·node.js·json
数据知道1 天前
PostgreSQL实战:详解如何用Python优雅地从PG中存取处理JSON
python·postgresql·json
缘空如是2 天前
基础工具包之JSON 工厂类
java·json·json切换
墨痕诉清风2 天前
CVS文件转Json格式
json·python3·cvs
数研小生2 天前
1688商品列表API:高效触达批发电商海量商品数据的技术方案
大数据·python·算法·信息可视化·json
devmoon3 天前
快速了解兼容 Ethereum 的 JSON-RPC 接口
开发语言·网络·rpc·json·区块链·智能合约·polkadot