I am trying to convert GameInfo.json file to List array by using Json.Utilities. And I want to manipulate this List data.
my items consist of 5 components(date, tournamentname, pos, rounds,total score)
here is my Json file(GameInfo.json)
{"Items":
[
{
"date":"11/06/16",
"tournamentName":"Shriners Hospitals for Children Open",
"pos":"2",
"rounds":"62 67 70 67 --",
"totalScore":"288"
},
{
"date":"11/06/16",
"tournamentName":"Shriners Hospitals for Children Open",
"pos":"2",
"rounds":"62 67 70 67 --",
"totalScore":"288"
}
]
}
Game info class include 5 data and and GameInfolist class will be use to make a list structure. GameInfo.json file is converted to GameInfo. After than, Game info is stored as string type(jsonstring) by using the unity.utilities, I try to store my string data into the List in order to manipulate my data. However, i can not reach the foreach loop.( I can't see the Debug.Log message). can you help me to fix my problem. Thank you for reading
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
[System.Serializable]
public class GameInfoList
{
public GameInfo gameInfo;
public string[,] Items = new string[2,5];
public List<GameInfo> list = new List<GameInfo>();
}
[System.Serializable]
public class GameInfo
{
public string date;
public string tournamentName;
public string pos;
public string rounds;
public string totalScore;
}
public class JsonDataConverter : MonoBehaviour
{
public string path = "GameInfo.json";
public string jsonstring;
GameInfoList gameInfoList;
public string JsonFileToString(string path)
{
Debug.Log("test");
string loadJsonfile = path.Replace(".json", "");
TextAsset loadedfile = Resources.Load<TextAsset>(loadJsonfile);
jsonstring = loadedfile.text;
Debug.Log("jsonstring:" + jsonstring);
return jsonstring;
}
public void Awake()
{
Debug.Log("testawake");
jsonstring = JsonFileToString(path);
gameInfoList = JsonUtility.FromJson<GameInfoList>(jsonstring);
}
public void Start()
{
foreach (var object in gameInfoList.list)
{
Debug.Log("reach to Inside Loop");
Debug.Log(object .date);
Debug.Log(object .pos);
Debug.Log(object .rounds);
Debug.Log(object .totalScore);
}
}
}