Hello guys i please need your help.
I am trying to make most simple way to bulk import my items in stock to my List in my object and want try it using JSON but i cant figure how to do it.
So i have my object Hardwares with List i want add to this list by json so i did this :
C#:
public void ImportHardware()
{
if(SaveManager.ImportExist())
{
string jsonHW = File.ReadAllText(Application.streamingAssetsPath + "/import/import.json");
Hardware newHW = JsonUtility.FromJson<Hardware>(jsonHW);
Debug.Log(newHW.imei);
}
Debug.Log("Import Hardware");
}
JSON:
{"type":1,"currentStock":"MIG_UPC","productCode":"FIXUPCTEL","owner":"FREE","state":0,"imei":"testjson1","returnOrder":""}
This is working as intended but i want put to this json file more of this hardware objects and then somhow add this objects in foreach loot to my Hardwares objects.
Is it possible?
Something like this :
c#
foreach(/*One line in JSON string*/)
{
hardwares.hardwareList.Add(/*this line as object Hardware*/);
}
JSON
{"type":1,"currentStock":"MIG_UPC","productCode":"FIXUPCTEL","owner":"FREE","state":0,"imei":"testjson1","returnOrder":""}
{"type":1,"currentStock":"MIG_UPC","productCode":"FIXUPCTEL","owner":"FREE","state":0,"imei":"testjson2","returnOrder":""}
{"type":1,"currentStock":"MIG_UPC","productCode":"FIXUPCTEL","owner":"FREE","state":0,"imei":"testjson3","returnOrder":""}
Do you guys have idea if this is possible? Thanks for help