美文网首页
unity Json转model

unity Json转model

作者: 游戏创作者 | 来源:发表于2020-03-04 10:41 被阅读0次

从服务器请求到webRequest.downloadHandler.text 是一个 json数据

Debug.Log(webRequest.downloadHandler.text);
image.png

首先我们创建一个model.cs脚本,内容为:

using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;


[Serializable]
public class Flower
{
    public Data data;
    public string msg;
}

[Serializable]
public class Data
{
    public int appversion;
    public int mathblockversion;
}

接下来解析json

Flower flower = JsonUtility.FromJson<Flower>(webRequest.downloadHandler.text);

现在想用appversion这个数据的话只要

Debug.Log(flower.data.appversion);

相关文章

网友评论

      本文标题:unity Json转model

      本文链接:https://www.haomeiwen.com/subject/pxaplhtx.html