C# 从JSON获取PNG
//这是我的3个脚本。在书皮中,我解析JSON,在CustomCell中,我将值分配给标签。然后在ListSource中,我将每个标签分配给当前行 //这是bookcover.CSC# 从JSON获取PNG,c#,json,unity3d,unity5,C#,Json,Unity3d,Unity5,//这是我的3个脚本。在书皮中,我解析JSON,在CustomCell中,我将值分配给标签。然后在ListSource中,我将每个标签分配给当前行 //这是bookcover.CS public ListSource dataSource; public ArrayList coversURL; public WWW imageURLWWW; public IEnumerator FetchBooks() { //A URL where the
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 ();
}
所以您正在尝试将PNG指定给文本标签吗?我这样做只是为了在Unity的listview中显示字符串文件。你知道如何显示PNG文件吗?就像我在列表视图中显示字符串文件一样。你可以从在线或本地存储中获取纹理,它将为你提供纹理2D对象。你不能在Unity中使用“arraylist”,请切换到普通列表。网络wit arraylist上有一些(非常旧的)示例代码,这会引起一些混淆。作为Unity中的一条规则,您永远不会真正使用数组,只需使用List(并且永远不要使用“arraylist”),谢谢您的建议
using UnityEngine;
using System.Collections;
using Tacticsoft;
using UnityEngine.UI;
public class CustomCell : TableViewCell {
public Text label1;
void Start()
{
label1 = (Text)GetComponent<Text> ();
}
}
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;
}