im trying to display a json list of items gathered from a web api, in unity, just to debug and then later in a text field for users. however the list always displays as empty and i cannot figure out why.
where i try to gather and display the data:
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Networking;
using UnityEngine.UI;
public class SearchThroughCards : MonoBehaviour {
public int size;
// Use this for initialization
void Start () {
StartCoroutine(GetCards());
}
// Update is called once per frame
IEnumerator GetCards()
{
UnityWebRequest www = UnityWebRequest.Get("https://www.ygohub.com/api/all_cards");
yield return www.Send();
if (www.isNetworkError)
{
Debug.Log(www.error);
}
else
{
// Show results as text
Debug.Log(www.downloadHandler.text);
RootCardList cardList = JsonUtility.FromJson<RootCardList>(www.downloadHandler.text);
size = cardList.card.Count;
Debug.Log(cardList.card);
foreach (string str in cardList.card)
{
Debug.Log(str);
}
}
}
}
"size" always gets debugged as 0 and the foreach loop actually never occurs my class for the data:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
[System.Serializable]
public class RootCardList
{
public string status;
public List<string> card;
}
a snippet of the json data im trying to convert:
{"status":"success","cards":["\"A\" Cell Breeding Device","\"A\" Cell Incubator","\"A\" Cell Recombination Device","\"A\" Cell Scatter Burst","1st Movement Solo","3-Hump Lacooda","30,000-Year White Turtle","4-Starred Ladybug of Doom","7","7 Colored Fish",