I am working on a unity project where i have to parse list of image url from JSON file and add it as source image to the dynamically spwaned scrollview content. I have created serializable class and dynamic spwaner , which will spwan the button on scrollview dynamically . How can i populate this list with the present JSON images URL i have . Thank you
using UnityEngine;
using System.Collections;
using UnityEngine.UI;
using UnityEngine.EventSystems;
using System.Collections.Generic;
[System.Serializable]
public class Person
{
public string name;
public Sprite icon;
}
public class CreateScrollList : MonoBehaviour
{
public GameObject namePrefab;
public List<Person> personList;
public Transform contentPanel;
// Use this for initialization
void Start()
{
PopulateList();
}
void PopulateList()
{
foreach (var person in personList)
{
GameObject newPerson = Instantiate(namePrefab) as GameObject;
NamePrefab generatedName = newPerson.GetComponent<NamePrefab>();
generatedName.nameLabel.text = person.name;
generatedName.icon = person.icon;
newPerson.transform.SetParent(contentPanel);
}
}
}
{
"array": [
"https://cdn1.iconfinder.com/data/icons/hawcons/32/699297-icon-68-document-file-app-512.png",
"https://d1gzq6u422bfcj.cloudfront.net/workflow_icons/99b9a7050c2f46b4b0b657e4ab0bedf4.png",
"https://cfcdnpull-creativefreedoml.netdna-ssl.com/wp-content/uploads/2016/06/New-instagram-icon.jpg"
]
}