C# 如何在unity中使用简单的JSON从数组中获取图像URL?
当我尝试将URL的JSON数组转换为字符串列表时,出现错误。错误如下所示:C# 如何在unity中使用简单的JSON从数组中获取图像URL?,c#,json,unity3d,C#,Json,Unity3d,当我尝试将URL的JSON数组转换为字符串列表时,出现错误。错误如下所示: Argument `#7' cannot convert `SimpleJSON.JSONNode' expression to type `System.Collections.Generic.List<string>' 但在最后一行Jnode[“product_images”]中显示了错误 " cannot convert `SimpleJSON.JSONNode' expression to type
Argument `#7' cannot convert `SimpleJSON.JSONNode' expression to type `System.Collections.Generic.List<string>'
但在最后一行Jnode[“product_images”]中显示了错误
" cannot convert `SimpleJSON.JSONNode' expression to type `System.Collections.Generic.List<string>' . "
“无法将'SimpleJSON.JSONNode'表达式转换为'System.Collections.Generic.List'类型。”
如何将它们添加到单个列表中?我的做法是使用另一个列表,然后根据assetid和相应的URL进行添加。为什么我不能使用SimpleJson将字符串中的JSONarray添加到列表中?product\u images字段比其他类型更复杂,因此您可以先尝试处理它。我没有您正在使用的JNode类型/库的经验,但我希望您能够按照以下思路做一些事情:
for (int i = 0; i < JNode.Count;i++)
{
List<string> Imagestring = new List<string>();
// See what type we get from the relevant field
for (int j = 0; j < JNode[i]["product_images"].Count;j++)
{
var imgeurls = JNode[i]["product_images"][j];
Imagestring.Add(imgeurls.ToString());
}
// Note - the last item is now the array created above
Alldetails.Add(new Handlepojo(JNode[i]["id"], JNode[i]["product_name"], JNode[i]["product_category_id"], JNode[i]["product_category_name"],
JNode[i]["product_description"], JNode[i]["product_price"],Imagestring));
}
for(int i=0;i
这是使用SimpleJSON向字符串列表添加链接的方法
JSONNode jnode = JSON.Parse(data);
JSONArray jLinks = jnode["product_images"].AsArray;
for (int i = 0; i < jLinks.Count; i++)
{
links.Add(jLinks[i]);
}
JSONNode jnode=JSON.Parse(数据);
JSONArray jLinks=jnode[“产品图片”]。AsArray;
对于(int i=0;i
这里的“数据”是json文件的文本格式。…imageUrlNode只返回一个字段…在这个字段中,我如何运行foreach循环?从您的代码中获取概念…根据我的需要进行编辑…:)您通过JNode[0][“product_images”][0]获取图像url。循环JNode[0][“产品图片”]
" cannot convert `SimpleJSON.JSONNode' expression to type `System.Collections.Generic.List<string>' . "
for (int i = 0; i < JNode.Count;i++)
{
List<string> Imagestring = new List<string>();
// See what type we get from the relevant field
for (int j = 0; j < JNode[i]["product_images"].Count;j++)
{
var imgeurls = JNode[i]["product_images"][j];
Imagestring.Add(imgeurls.ToString());
}
// Note - the last item is now the array created above
Alldetails.Add(new Handlepojo(JNode[i]["id"], JNode[i]["product_name"], JNode[i]["product_category_id"], JNode[i]["product_category_name"],
JNode[i]["product_description"], JNode[i]["product_price"],Imagestring));
}
JSONNode jnode = JSON.Parse(data);
JSONArray jLinks = jnode["product_images"].AsArray;
for (int i = 0; i < jLinks.Count; i++)
{
links.Add(jLinks[i]);
}