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 天前
Spring的过滤器获取请求体中JSON参数,同时解决Controller获取不到请求体参数的问题。
java·spring·json
whisperrr.1 天前
【JavaWeb12】数据交换与异步请求:JSON与Ajax的绝妙搭配是否塑造了Web的交互革命?
前端·ajax·json
子非衣2 天前
MySQL修改JSON格式数据示例
android·mysql·json
林的快手4 天前
伪类选择器
android·前端·css·chrome·ajax·html·json
css趣多多4 天前
初步安装和使用vant组件库,使用css变量定制vant主题样式 ,小程序的API Promise化,调用promise化之API
json
Web极客码5 天前
WordPress“更新失败,响应不是有效的JSON响应”问题的修复
json·github·wordpress
gywl7 天前
Spring Web MVC入门
spring·json·mvc·注解·cookie·session
运维小文8 天前
Mongodb数据管理
数据库·mongodb·json·非关系数据库·文档型数据库
玉阳软件yuyangdev_cn8 天前
铁塔电单车协议对接电单车TCP json协议对接成熟充电桩系统搭建低速充电桩TCP 接口规范
网络·tcp/ip·json·铁塔协议
m0_748232928 天前
SpringCloud系列教程:微服务的未来 (五)枚举处理器、JSON处理器、分页插件实现
spring cloud·微服务·json