Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/277.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
JSON(Windows 10通用C#)_C#_Json_Windows - Fatal编程技术网

JSON(Windows 10通用C#)

JSON(Windows 10通用C#),c#,json,windows,C#,Json,Windows,以上是我的JSON输出 我可以设法获得其他单一输出,如产品代码等。 但是想得到关于如何获得“img[0]”和“img[1]”图像链接的帮助。下面是我的代码 [ { "img":[ "http://inventory.vibhavpatil.com/productimages/912b4loRgiL._UL1500_.jpg", "http://inventory.vibhavpatil.com/productimages/f

以上是我的JSON输出

我可以设法获得其他单一输出,如产品代码等。 但是想得到关于如何获得“img[0]”和“img[1]”图像链接的帮助。下面是我的代码

[
    {
        "img":[
            "http://inventory.vibhavpatil.com/productimages/912b4loRgiL._UL1500_.jpg",
            "http://inventory.vibhavpatil.com/productimages/fdsfdsf.jpg"
        ],
        "Colour":[
            "Grey"
        ],
        "Size":[
            "Medium"
        ],
        "productcode":"0001",
        "productname":"Alan Jones Men\u0027s Cotton Printed T-Shirt",
        "productbrand":"sousamoda",
        "productcat":"clothing",
        "productsubcat":"t-shirt",
        "productmindec":"Look stylish and impressive",
        "actualprice":"899",
        "bestprice":"419",
        "quantity":"5",
        "designer":"Adidas"
    }
]
类详细信息
{
公共字符串productcode{get;set;}
公共字符串productname{get;set;}
公共字符串productbrand{get;set;}
公共字符串productcat{get;set;}
公共字符串productsubcat{get;set;}
公共字符串productmindec{get;set;}
公共字符串实际价格{get;set;}
公共字符串bestprice{get;set;}
公共字符串数量{get;set;}
公共字符串设计器{get;set;}
公共列表img=新列表();
公共列表颜色=新列表();
公共列表大小=新列表();
}
我的C代码

Array obj=JArray.Parse(urlContents);
for(int i=0;i
我强烈建议使用Newtonsoft JSON属性,而不是手动解析。只需输入“Nuget gallery”并输入JSON,Newtonsoft软件包就可以在搜索结果中排名第一


使用它,坚持它,热爱它。(c)

如果要解析JSON,则无需单独获取每个项目

只需使用一些JSON工具,如,并在一行中完成此操作:

Array obj = JArray.Parse(urlContents);          

for (int i = 0; i < obj.Count; i++)
{

    JObject row = JObject.Parse(obj[i].ToString());
    try
    {
        var item1 = new FullDetails();
        item1.productcode = row["productcode"].ToString();
        item1.productname = row["productname"].ToString();
        item1.productmindec = row["productmindec"].ToString();                   
        item1.actualprice = row["actualprice"].ToString();
        item1.bestprice = row["bestprice"].ToString();
        item1.productbrand = row["productbrand"].ToString();
        item1.productcat = row["productcat"].ToString();
        item1.productsubcat = row["productsubcat"].ToString();
        item1.quantity = row["quantity"].ToString();
        item1.designer = row["designer"].ToString();

        item1.img[0]= row["img"][0].ToString();                

        list1.Items.Add(item1);
    }
    catch
    {

    }
}
var obj=Newtonsoft.Json.JsonConvert.DeserializeObject(序列化);

我正在将其反序列化为一个数组(
FullDetails[]
),因为您的URL返回一个数组(内容由
[
]
括起),即使数组只有一项。

共享Json代码,但不共享image@gencklavyeler链接将提供jsonoutput@SirRufo我能得到代码帮助吗?我想他说得很清楚:将JSON作为格式化的纯文本,而不是图像,也不是链接发布。
Array obj = JArray.Parse(urlContents);          

for (int i = 0; i < obj.Count; i++)
{

    JObject row = JObject.Parse(obj[i].ToString());
    try
    {
        var item1 = new FullDetails();
        item1.productcode = row["productcode"].ToString();
        item1.productname = row["productname"].ToString();
        item1.productmindec = row["productmindec"].ToString();                   
        item1.actualprice = row["actualprice"].ToString();
        item1.bestprice = row["bestprice"].ToString();
        item1.productbrand = row["productbrand"].ToString();
        item1.productcat = row["productcat"].ToString();
        item1.productsubcat = row["productsubcat"].ToString();
        item1.quantity = row["quantity"].ToString();
        item1.designer = row["designer"].ToString();

        item1.img[0]= row["img"][0].ToString();                

        list1.Items.Add(item1);
    }
    catch
    {

    }
}
var obj = Newtonsoft.Json.JsonConvert.DeserializeObject<FullDetails[]>(serialized);