首页 > 其他分享 >Unity反序列天气API的JSON

Unity反序列天气API的JSON

时间:2022-11-01 11:25:03浏览次数:60  
标签:www string int Unity System JSON API public wind

心知天气:https://www.seniverse.com/

JSON:

{
  "results": [
    {
      "location": {
        "id": "C23NB62W20TF",
        "name": "西雅图",
        "country": "US",
        "path": "西雅图,华盛顿州,美国",
        "timezone": "America/Los_Angeles",
        "timezone_offset": "-07:00"
      },
      "now": {
        "text": "多云", 
        "code": "4", 
        "temperature": "14", 
        "feels_like": "14", 
        "pressure": "1018", 
        "humidity": "76", 
        "visibility": "16.09", 
        "wind_direction": "西北", 
        "wind_direction_degree": "340", 
        "wind_speed": "8.05", 
        "wind_scale": "2", 
        "clouds": "90", 
        "dew_point": "-12" 
      },
      "last_update": "2015-09-25T22:45:00-07:00" 
    }
  ]
}

 

反序列:

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

[System.Serializable]
public class listres
{
    public List<ResponseData> results = new List<ResponseData>();
}

[System.Serializable]
public class ResponseData
{
    public locationdata location;
    public nowdata now;
    public string last_update;
}

[System.Serializable]
public class locationdata
{
    public string id;
    public string name;
    public string country;
    public string path;
    public string timezone;
    public string timezone_offset;
}
[System.Serializable]
public class nowdata
{
    public string text;
    public int code;
    public int temperature;
    public int feels_like;
    public int pressure;
    public int humidity;
    public float visibility;
    public string wind_direction;
    public int wind_direction_degree;
    public float wind_speed;
    public int wind_scale;
    public int clouds;
    public string dew_point;
}

public class WeatherQuerier : MonoBehaviour
{
    // Start is called before the first frame update
    IEnumerator Start()
    {
        WWW www=new WWW("https://api.seniverse.com/v3/weather/now.json?key=SGRa_X2yE0sr74OOd&location=beijing&language=zh-Hans&unit=c");
        yield return www;
        print(www.text);
        listres respon =JsonUtility.FromJson<listres>(www.text);
        print(respon.results[0].location.path);
    }

    // Update is called once per frame
    void Update()
    {
        
    }
}

 

标签:www,string,int,Unity,System,JSON,API,public,wind
From: https://www.cnblogs.com/resucase/p/16847059.html

相关文章

  • unity3d:最简单的服务器,把收到消息发回客户端
    usingUnityEngine;usingSystem.Collections;usingSystem.Collections.Generic;usingSystem.Net.Sockets;usingSystem.Net;usingSystem.Threading;usingSystem;usin......
  • unity3d:ui跟着gameobject移动
    usingSystem.Collections;usingSystem.Collections.Generic;usingUnityEngine;publicclassUiFollowObj:MonoBehaviour{Transformm_trans;publicTransform......
  • unity3d:protobuf .java转.cs
    服务器端定义好protobuf结构,放unity编辑器中生成.cs的结构usingSystem.Collections;usingSystem.Collections.Generic;usingUnityEngine;usingUnityEditor;usingSystem......
  • unity3d:复制选中物体transform信息到剪切板
    usingSystem.Collections;usingSystem.Collections.Generic;usingUnityEngine;usingUnityEditor;publicclassSaveTransInfo:EditorWindow{[MenuItem("SaveTrans......
  • unity3d:ugui 每个字间隔间距
    usingUnityEngine;usingSystem.Collections;usingUnityEngine.UI;usingSystem;usingSystem.Collections.Generic;publicclassLine{privateint_startVertexInde......
  • Unity3D :Mob SMSSDK 运行崩溃
    报错信息android.content.ActivityNotFoundException:Unabletofindexplicitactivityclass{com.shuiying.smsm09061/com.mob.tools.MobUIShell};haveyoudeclaredt......
  • unity3d:显示FPS
    usingSystem.Collections;usingSystem.Collections.Generic;usingUnityEngine;publicclassFPSShow:MonoBehaviour{privatevoidOnGUI(){stringte......
  • unity3d:编辑器脚本,替换选中物体的材质
    usingSystem.Collections;usingSystem.Collections.Generic;usingUnityEngine;usingUnityEditor;publicclassChangeMat:MonoBehaviour{[MenuItem("Tools/Chang......
  • unity3d:xlua 加载自定义Loader
    在xLua加自定义loader是很简单的,只涉及到一个接口:publicdelegatebyte[]CustomLoader(refstringfilepath);publicvoidLuaEnv.AddLoader(CustomLoaderloader)通过A......
  • unity3d:xlua hotfix 官方例子
    1.新建工程,xlua文件夹与Plugins文件夹放入assets,tools放assets同级目录2.添加宏:HOTFIX_ENABLE3.D:\WorkSoft\unity2017.2.0\Editor\Data\Managed3个文件Unity.Cecil.dll,U......