123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135 |
- using LitJson;
- using Newtonsoft.Json;
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- public class TestJson : MonoBehaviour
- {
- string message;
- // Start is called before the first frame update
- void Start()
- {
- // ToJson();
- StartCoroutine(StartText2());
- // StartText2();
- }
- // Update is called once per frame
- void Update()
- {
- }
- IEnumerator StartText2()
- {
-
- //读取streamingasset
- WWW www = new WWW(Application.streamingAssetsPath + "/co2_emission.json");
-
- yield return www;
- message = www.text;
- message = message.Replace(" ", "");
- Debug.Log(message);
- Dictionary<string, Dictionary<string, JData>> rotaDics = JsonConvert.DeserializeObject<Dictionary<string, Dictionary<string, JData>>>(message);
- JRota rota = new JRota();
- message = message.Substring(1, message.Length - 2);//把message 最外面{} 去掉
- string[] str = message.Split(':');
- rota.time = str[0]; // 拿到时间
- for (int i = 0; i < message.Length; i++)
- {
- if(message[i] == ':')
- {
- message.Substring(i + 1, message.Length - 1); // 去除掉时间 : 前的字符
- }
- }
- Dictionary<string, JData> rotaDic = JsonConvert.DeserializeObject<Dictionary<string, JData>>(message);
- rota.rotaDic = rotaDic;
- foreach (var item in rotaDic)
- {
- Debug.Log(item.Value.AVIATION);
- }
- //if (message != "")
- //{
- // JsonData data = JsonMapper.ToObject(message);
- // Debug.Log(data["2020-01-01"]["UnitedArabEmirates"]["total_daily_emission"]);
- // Debug.Log(data["2020-01-01"][0]);
- // foreach (JsonData item in data["2020-01-01"][0])
- // {
- // Debug.Log(item["total_daily_emission"]);
- // }
- // //JRota Jrota = JsonMapper.ToObject<JRota>(message);
- // //Debug.Log(Jrota.listJdata.Count);
- //}
- }
-
- void ToJson()
- {
- Debug.Log(message);
- JsonData data = JsonMapper.ToObject(message);
- Debug.Log(data["2020-01-01"][0].ToString());
- //foreach (JData item in data["2020-01-01"])
- //{
- // Debug.Log
- //}
-
- }
-
-
- }
- public class JRota
- {
- public string time { get; set; }
- public Dictionary<string, JData> rotaDic { get; set; }
- }
- public class JData
- {
- public float total_daily_emission { get; set; }
- public float total_daily_emission_re { get; set; }
- public float CIlevel { get; set; }
- public float emission_per_second { get; set; }
- public float emission_per_second_re { get; set; }
- public float POWER_re { get; set; }
- public float POWER_pt { get; set; }
- public float POWER_re_pt { get; set; }
- public float INDUSTRY { get; set; }
- public float INDUSTRY_re{ get; set; }
- public float INDUSTRY_pt{ get; set; }
- public float INDUSTRY_re_pt{ get; set; }
- public float SURFACE_TRANSPORT{ get; set; }
- public float SURFACE_TRANSPORT_re{ get; set; }
- public float SURFACE_TRANSPORT_pt{ get; set; }
- public float SURFACE_TRANSPORT_re_pt{ get; set; }
- public float PUBLIC{ get; set; }
- public float PUBLIC_re{ get; set; }
- public float PUBLIC_pt{ get; set; }
- public float PUBLIC_re_pt{ get; set; }
- public float RESIDENTIAL{ get; set; }
- public float RESIDENTIAL_re{ get; set; }
- public float RESIDENTIAL_pt{ get; set; }
- public float RESIDENTIAL_re_pt{ get; set; }
- public float AVIATION{ get; set; }
- public float AVIATION_re{ get; set; }
- public float AVIATION_pt{ get; set; }
- public float AVIATION_re_pt{ get; set; }
- }
- public class Argentina : JData
- {
- }
|