Help with API JSON Please!!

Hi yall,

so i’m trying to get air quality data in json and it was working yesterday but somehow stopped. And it’s driving me crazy! cuz the deadline is soon. FYI I’m not a coder at all so please be nice and easy. And most importantly help!!!

Here’s the code:

using System;
using System.Collections;
using System.Collections.Generic;
using System.Globalization;
using UnityEngine;
using UnityEngine.Networking;
using UnityEngine.UI;

public class AirData : MonoBehaviour
{
    private string url = "http://openapi....";

    public AirInfo Info;
    private float timer;
    public float minutesBetweenUpdate;
    public Text pm10ValueText;
    public Text pm25ValueText;
    public Text so2ValueText;
    public Text coValueText;
    public Text o3ValueText;
    public Text no2ValueText;


    void Update()
    {
        if (timer <= 0)
        {
            StartCoroutine(GetAirData());
            timer = minutesBetweenUpdate * 60;

            pm10ValueText.text = "PM10:  " + Info.list.pm10Value;
            pm25ValueText.text = "PM25 :  " + Info.list.pm25Value;
            so2ValueText.text = "SO2 :  " + Info.list.so2Value;
            coValueText.text = "CO :  " + Info.list.coValue;
            o3ValueText.text = " O3 :  " + Info.list.o3Value;
            no2ValueText.text = "NO2  :  " + Info.list.no2Value;
        }
        else
        {
            timer -= Time.deltaTime;
        }
    }

    IEnumerator GetAirData()
    {
        UnityWebRequest www = UnityWebRequest.Get(url);
        {
            yield return www.SendWebRequest();

            if (www.isNetworkError)
            {
                yield break;
            }

            Info = JsonUtility.FromJson<AirInfo>(www.downloadHandler.text);

        }
    }
    [Serializable]

    public class AirInfo
    {
        public List list;
      //  public Parm parm;
     //   public ArpltnInforInqireSvcVo ArpltnInforInqireSvcVo;
     //   public int totalCount;
    }

    [Serializable]

    public class List
    {
        public string coValue;
        public string no2Value;
        public string o3Value;
        public string pm10Value;
        public string pm25Value;
        public string so2Value;

    }
}

And this is the OG JSON but I only need the 6 values.

public class List
    {
        public string _returnType { get; set; }
        public string coGrade { get; set; }
        public string coValue { get; set; }
        public string dataTerm { get; set; }
        public string dataTime { get; set; }
        public string khaiGrade { get; set; }
        public string khaiValue { get; set; }
        public string mangName { get; set; }
        public string no2Grade { get; set; }
        public string no2Value { get; set; }
        public string numOfRows { get; set; }
        public string o3Grade { get; set; }
        public string o3Value { get; set; }
        public string pageNo { get; set; }
        public string pm10Grade { get; set; }
        public string pm10Grade1h { get; set; }
        public string pm10Value { get; set; }
        public string pm10Value24 { get; set; }
        public string pm25Grade { get; set; }
        public string pm25Grade1h { get; set; }
        public string pm25Value { get; set; }
        public string pm25Value24 { get; set; }
        public string resultCode { get; set; }
        public string resultMsg { get; set; }
        public int rnum { get; set; }
        public string serviceKey { get; set; }
        public string sidoName { get; set; }
        public string so2Grade { get; set; }
        public string so2Value { get; set; }
        public string stationCode { get; set; }
        public string stationName { get; set; }
        public string totalCount { get; set; }
        public string ver { get; set; }
    }

    public class Parm
    {
        public string _returnType { get; set; }
        public string coGrade { get; set; }
        public string coValue { get; set; }
        public string dataTerm { get; set; }
        public string dataTime { get; set; }
        public string khaiGrade { get; set; }
        public string khaiValue { get; set; }
        public string mangName { get; set; }
        public string no2Grade { get; set; }
        public string no2Value { get; set; }
        public string numOfRows { get; set; }
        public string o3Grade { get; set; }
        public string o3Value { get; set; }
        public string pageNo { get; set; }
        public string pm10Grade { get; set; }
        public string pm10Grade1h { get; set; }
        public string pm10Value { get; set; }
        public string pm10Value24 { get; set; }
        public string pm25Grade { get; set; }
        public string pm25Grade1h { get; set; }
        public string pm25Value { get; set; }
        public string pm25Value24 { get; set; }
        public string resultCode { get; set; }
        public string resultMsg { get; set; }
        public int rnum { get; set; }
        public string serviceKey { get; set; }
        public string sidoName { get; set; }
        public string so2Grade { get; set; }
        public string so2Value { get; set; }
        public string stationCode { get; set; }
        public string stationName { get; set; }
        public string totalCount { get; set; }
        public string ver { get; set; }
    }

    public class ArpltnInforInqireSvcVo
    {
        public string _returnType { get; set; }
        public string coGrade { get; set; }
        public string coValue { get; set; }
        public string dataTerm { get; set; }
        public string dataTime { get; set; }
        public string khaiGrade { get; set; }
        public string khaiValue { get; set; }
        public string mangName { get; set; }
        public string no2Grade { get; set; }
        public string no2Value { get; set; }
        public string numOfRows { get; set; }
        public string o3Grade { get; set; }
        public string o3Value { get; set; }
        public string pageNo { get; set; }
        public string pm10Grade { get; set; }
        public string pm10Grade1h { get; set; }
        public string pm10Value { get; set; }
        public string pm10Value24 { get; set; }
        public string pm25Grade { get; set; }
        public string pm25Grade1h { get; set; }
        public string pm25Value { get; set; }
        public string pm25Value24 { get; set; }
        public string resultCode { get; set; }
        public string resultMsg { get; set; }
        public int rnum { get; set; }
        public string serviceKey { get; set; }
        public string sidoName { get; set; }
        public string so2Grade { get; set; }
        public string so2Value { get; set; }
        public string stationCode { get; set; }
        public string stationName { get; set; }
        public string totalCount { get; set; }
        public string ver { get; set; }
    }

    public class Example
    {
        public IList<List> list { get; set; }
        public Parm parm { get; set; }
        public ArpltnInforInqireSvcVo ArpltnInforInqireSvcVo { get; set; }
        public int totalCount { get; set; }
    }

It would help if you explained what was going wrong.

duh, right… haha

the values are not printing in the inspector…

On lines 31-36 you’re trying to copy values from Info before Info is populated would be my guess.

Try moving those lines to the end of the coroutine - line 56

Thanks but no luck. :frowning: I can print it to the console through Debug. I just can’t get it to print in the inspector. Arggghhh. I totally had it working yesterday too. I feel so dumb~