从JSON获取PNG

时间:2016-03-21 10:07:55

标签: c# json unity3d unity5

//这些是我有的3个脚本。在BookCovers中,我解析了JSON,在CustomCell中,我将值分配给Label。然后在ListSource中,我将每个Label分配给当前行。

//这是BOOKCOVERS.CS

 public ListSource dataSource;
    public ArrayList coversURL;
    public WWW imageURLWWW;

    public IEnumerator FetchBooks()
    {
        //A URL where the image is stored
        string url = "http: myLink";  

        //Call the WWW class constructor
        imageURLWWW = new WWW(url);
        Debug.Log ("blla blla blla");
        yield return imageURLWWW;

        JsonData imageUrls = JsonMapper.ToObject(imageURLWWW.text);
        print (imageUrls);

        coversURL = new ArrayList ();

        for (int i = 0; i < imageUrls.Count; i++) 
        {  
            JsonData book = imageUrls [i];
            string url1 = (string) book ["url_cover_img"];
            coversURL.Add (url1);
        }

        updateSurce ();
        foreach (string urls in coversURL) {

            Debug.Log (urls);
        }
        Debug.Log ("Fetch is completed");

        Debug.Log ("Update Source");
        dataSource.sourcce = coversURL;
        Debug.Log ("Size " + dataSource.sourcce.Count);
        dataSource.tableView.ReloadData ();


    }

//这是CUSTOMCELL.CS

  using UnityEngine;
    using System.Collections;
    using Tacticsoft;
    using UnityEngine.UI;

public class CustomCell : TableViewCell {

    public Text label1;

    void Start()
    {
        label1 = (Text)GetComponent<Text> ();
    }

}

//这是列表来源.CS

 public TableViewCell GetCellForRowInTableView(TableView tableView, int row)
        {
            CustomCell cell = tableView.GetReusableCell("asdasdasds") as CustomCell;
            if (cell == null) 
            {
                cell = (CustomCell)GameObject.Instantiate(cellType);

            }

            Debug.Log ("Get cells");
            cell.label1.text=(string)sourcce[row];
            return cell;
        }

0 个答案:

没有答案