Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/json/13.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
C# Json序列化为空_C#_Json_Json Deserialization - Fatal编程技术网

C# Json序列化为空

C# Json序列化为空,c#,json,json-deserialization,C#,Json,Json Deserialization,我对Json并没有太多的需求,所以对我来说,Json仍然是一种令人头疼的挫败感。如果这是一个骗局,我很抱歉,但我在搜索中发现的一切都与不同的问题有关 我正在尝试使用沃尔玛API,我的数据很好(我在下面附上了一条记录供参考)。我能找到的所有现有问题似乎都是处理传入的空数据。这是关于空数据的输出 问题/疑问:我对API的调用产生了巨大的回报——1000条记录(385MB未压缩)。当我反序列化时,我没有得到任何异常,我仍然得到1000条记录,但返回列表中的每个属性都为null或0。因此,Json返回一

我对Json并没有太多的需求,所以对我来说,Json仍然是一种令人头疼的挫败感。如果这是一个骗局,我很抱歉,但我在搜索中发现的一切都与不同的问题有关

我正在尝试使用沃尔玛API,我的数据很好(我在下面附上了一条记录供参考)。我能找到的所有现有问题似乎都是处理传入的空数据。这是关于空数据的输出

问题/疑问:我对API的调用产生了巨大的回报——1000条记录(385MB未压缩)。当我反序列化时,我没有得到任何异常,我仍然得到1000条记录,但返回列表中的每个属性都为null或0。因此,Json返回一个泛型列表,该列表有记录,记录不为null,但每个记录中的所有值/属性都为null(如果为数字,则为0)

我在序列化过程中设置了一个断点,可以正确地看到json数据。它只是显示为null/0

如果您有任何想法,我将非常感谢您提供的任何帮助。感谢您花时间阅读本文,并提前感谢您提供的任何帮助

意外结果:

Item_ID itemId  parentItemId    name    salePrice   upc shortDescription    longDescription brandName   thumbnailImage  mediumImage largeImage  productTrackingUrl  ninetySevenCentShipping standardShipRate    size    color   marketplace shipToStore freeShipToStore productUrl  customerRating  numReviews  customerRatingImage rollBack    bundle  clearance   stock   gender  age freeShippingOver50Dollars   availableOnline
 1  0   0   NULL    0   NULL    NULL    NULL    NULL    NULL    NULL    NULL    NULL    0   0   NULL    NULL    0   0   0   NULL    NULL    0   NULL    0   0   0   NULL    NULL    NULL    0   0
public API_Json_Special_Feeds.RootObject testExistingJson()
    {
        string json = "";
        //I saved a response to a text file so I don't overload the API with testing. The same problem happens whether or not I load from API or text file.
        using(TextReader tr = new StreamReader(@"C:jsonsingle.txt"))
        {
            json = tr.ReadToEnd();//string
        }
        var serializer = new DataContractJsonSerializer(typeof(API_Json_Special_Feeds.RootObject));

        var ms = new MemoryStream(Encoding.UTF8.GetBytes(json));
        var data = (API_Json_Special_Feeds.RootObject)serializer.ReadObject(ms);
         return data;
    }
 {"items":[ {
 "itemId" : 12321374,
 "parentItemId" : 12321374,
 "name" : "Castle Tent Loft Bed w/ Slide ; Under Bed Storage, Blue",
 "salePrice" : 369.0,
 "upc" : "081438383996",
 "shortDescription" : "Finished in White powder coat with Blue and Red Microfiber fabric tent",
 "longDescription" : "Fun Castle Tent Bunk Bed with Slide includes a tent over twin bed and a covered hiding place below. The covered hiding place below can also be used as under bed storage. The top of the slide is tented with a tower with peek through, fold down window covers. <ul class="noindent"><li>Finished in White powder coat with Blue and Red Microfiber fabric tent, 100% polyester.</li><li>Uses a standard twin size mattress (sold separately).</li><li>Only use a twin size mattress that is 74-75" long and 37.5-38.5" wide.</li><li>Bunk bed is tested and certified by an independent testing laboratory to meet all minimum requirements of ASTM F1427-07 and U.S. CFR 1213 and 1513.</li><li>Some assembly required. 79-3/4" x 101-1/4" x 92" tall.</li></ul>",
 "brandName" : "Castle",
 "thumbnailImage" : "https://i5.walmartimages.com/asr/a1bac83b-68f2-427e-82ac-97ce1e11b0c6_1.f18ff9fc14c7aca2d9c92c81f4b5c8ba.jpeg?odnHeight=100&odnWidth=100&odnBg=ffffff",
 "mediumImage" : "https://i5.walmartimages.com/asr/a1bac83b-68f2-427e-82ac-97ce1e11b0c6_1.f18ff9fc14c7aca2d9c92c81f4b5c8ba.jpeg?odnHeight=180&odnWidth=180&odnBg=ffffff",
 "largeImage" : "https://i5.walmartimages.com/asr/a1bac83b-68f2-427e-82ac-97ce1e11b0c6_1.f18ff9fc14c7aca2d9c92c81f4b5c8ba.jpeg?odnHeight=450&odnWidth=450&odnBg=ffffff",
 "productTrackingUrl" : "http://linksynergy.walmart.com/fs-bin/click?id=|LSNID|&offerid=223073.7200&type=14&catid=8&subid=0&hid=7200&tmpid=1082&RD_PARM1=http%253A%252F%252Fwww.walmart.com%252Fip%252FCastle-Tent-Loft-Bed-w-Slide--Under-Bed-Storage-Blue%252F12321374%253Faffp1%253D%257Capk%257C%2526affilsrc%253Dapi",
 "ninetySevenCentShipping" : false,
 "standardShipRate" : 0.0,
 "size" : "Twin",
 "color" : "Blue",
 "marketplace" : false,
 "shipToStore" : true,
 "freeShipToStore" : true,
 "productUrl" : "http://c.affil.walmart.com/t/api00rb?l=http%3A%2F%2Fwww.walmart.com%2Fip%2FCastle-Tent-Loft-Bed-w-Slide--Under-Bed-Storage-Blue%2F12321374%3Faffp1%3D%7Capk%7C%26affilsrc%3Dapi%26veh%3Daff%26wmlspartner%3Dreadonlyapi",
 "customerRating" : "4.574",
 "numReviews" : 54,
 "customerRatingImage" : "http://i2.walmartimages.com/i/CustRating/4_6.gif",
 "rollBack" : true,
 "bundle" : true,
 "clearance" : false,
 "stock" : "Available",
 "gender" : "Boys",
 "age" : "Child",
 "freeShippingOver50Dollars" : true,
 "availableOnline" : true
}]
}
public class API_Json_Special_Feeds
{
    [DataContract]
    public class Item
    {
        public int itemId { get; set; }
        public int parentItemId { get; set; }
        public string name { get; set; }
        public double salePrice { get; set; }
        public string upc { get; set; }
        public string shortDescription { get; set; }
        public string longDescription { get; set; }
        public string brandName { get; set; }
        public string thumbnailImage { get; set; }
        public string mediumImage { get; set; }
        public string largeImage { get; set; }
        public string productTrackingUrl { get; set; }
        public bool ninetySevenCentShipping { get; set; }
        public double standardShipRate { get; set; }
        public string size { get; set; }
        public string color { get; set; }
        public bool marketplace { get; set; }
        public bool shipToStore { get; set; }
        public bool freeShipToStore { get; set; }
        public string productUrl { get; set; }
        public string customerRating { get; set; }
        public int numReviews { get; set; }
        public string customerRatingImage { get; set; }
        public bool rollBack { get; set; }
        public bool bundle { get; set; }
        public bool clearance { get; set; }
        public string stock { get; set; }
        public string gender { get; set; }
        public string age { get; set; }
        public bool freeShippingOver50Dollars { get; set; }
        public bool availableOnline { get; set; }
    }
    [DataContract]
    public class RootObject
    {
        [DataMember]
        public List<Item> items { get; set; }
    }
}
序列化逻辑:

Item_ID itemId  parentItemId    name    salePrice   upc shortDescription    longDescription brandName   thumbnailImage  mediumImage largeImage  productTrackingUrl  ninetySevenCentShipping standardShipRate    size    color   marketplace shipToStore freeShipToStore productUrl  customerRating  numReviews  customerRatingImage rollBack    bundle  clearance   stock   gender  age freeShippingOver50Dollars   availableOnline
 1  0   0   NULL    0   NULL    NULL    NULL    NULL    NULL    NULL    NULL    NULL    0   0   NULL    NULL    0   0   0   NULL    NULL    0   NULL    0   0   0   NULL    NULL    NULL    0   0
public API_Json_Special_Feeds.RootObject testExistingJson()
    {
        string json = "";
        //I saved a response to a text file so I don't overload the API with testing. The same problem happens whether or not I load from API or text file.
        using(TextReader tr = new StreamReader(@"C:jsonsingle.txt"))
        {
            json = tr.ReadToEnd();//string
        }
        var serializer = new DataContractJsonSerializer(typeof(API_Json_Special_Feeds.RootObject));

        var ms = new MemoryStream(Encoding.UTF8.GetBytes(json));
        var data = (API_Json_Special_Feeds.RootObject)serializer.ReadObject(ms);
         return data;
    }
 {"items":[ {
 "itemId" : 12321374,
 "parentItemId" : 12321374,
 "name" : "Castle Tent Loft Bed w/ Slide ; Under Bed Storage, Blue",
 "salePrice" : 369.0,
 "upc" : "081438383996",
 "shortDescription" : "Finished in White powder coat with Blue and Red Microfiber fabric tent",
 "longDescription" : "Fun Castle Tent Bunk Bed with Slide includes a tent over twin bed and a covered hiding place below. The covered hiding place below can also be used as under bed storage. The top of the slide is tented with a tower with peek through, fold down window covers. &lt;ul class=&quot;noindent&quot;&gt;&lt;li&gt;Finished in White powder coat with Blue and Red Microfiber fabric tent, 100% polyester.&lt;/li&gt;&lt;li&gt;Uses a standard twin size mattress (sold separately).&lt;/li&gt;&lt;li&gt;Only use a twin size mattress that is 74-75&quot; long and 37.5-38.5&quot; wide.&lt;/li&gt;&lt;li&gt;Bunk bed is tested and certified by an independent testing laboratory to meet all minimum requirements of ASTM F1427-07 and U.S. CFR 1213 and 1513.&lt;/li&gt;&lt;li&gt;Some assembly required. 79-3/4&quot; x 101-1/4&quot; x 92&quot; tall.&lt;/li&gt;&lt;/ul&gt;",
 "brandName" : "Castle",
 "thumbnailImage" : "https://i5.walmartimages.com/asr/a1bac83b-68f2-427e-82ac-97ce1e11b0c6_1.f18ff9fc14c7aca2d9c92c81f4b5c8ba.jpeg?odnHeight=100&odnWidth=100&odnBg=ffffff",
 "mediumImage" : "https://i5.walmartimages.com/asr/a1bac83b-68f2-427e-82ac-97ce1e11b0c6_1.f18ff9fc14c7aca2d9c92c81f4b5c8ba.jpeg?odnHeight=180&odnWidth=180&odnBg=ffffff",
 "largeImage" : "https://i5.walmartimages.com/asr/a1bac83b-68f2-427e-82ac-97ce1e11b0c6_1.f18ff9fc14c7aca2d9c92c81f4b5c8ba.jpeg?odnHeight=450&odnWidth=450&odnBg=ffffff",
 "productTrackingUrl" : "http://linksynergy.walmart.com/fs-bin/click?id=|LSNID|&offerid=223073.7200&type=14&catid=8&subid=0&hid=7200&tmpid=1082&RD_PARM1=http%253A%252F%252Fwww.walmart.com%252Fip%252FCastle-Tent-Loft-Bed-w-Slide--Under-Bed-Storage-Blue%252F12321374%253Faffp1%253D%257Capk%257C%2526affilsrc%253Dapi",
 "ninetySevenCentShipping" : false,
 "standardShipRate" : 0.0,
 "size" : "Twin",
 "color" : "Blue",
 "marketplace" : false,
 "shipToStore" : true,
 "freeShipToStore" : true,
 "productUrl" : "http://c.affil.walmart.com/t/api00rb?l=http%3A%2F%2Fwww.walmart.com%2Fip%2FCastle-Tent-Loft-Bed-w-Slide--Under-Bed-Storage-Blue%2F12321374%3Faffp1%3D%7Capk%7C%26affilsrc%3Dapi%26veh%3Daff%26wmlspartner%3Dreadonlyapi",
 "customerRating" : "4.574",
 "numReviews" : 54,
 "customerRatingImage" : "http://i2.walmartimages.com/i/CustRating/4_6.gif",
 "rollBack" : true,
 "bundle" : true,
 "clearance" : false,
 "stock" : "Available",
 "gender" : "Boys",
 "age" : "Child",
 "freeShippingOver50Dollars" : true,
 "availableOnline" : true
}]
}
public class API_Json_Special_Feeds
{
    [DataContract]
    public class Item
    {
        public int itemId { get; set; }
        public int parentItemId { get; set; }
        public string name { get; set; }
        public double salePrice { get; set; }
        public string upc { get; set; }
        public string shortDescription { get; set; }
        public string longDescription { get; set; }
        public string brandName { get; set; }
        public string thumbnailImage { get; set; }
        public string mediumImage { get; set; }
        public string largeImage { get; set; }
        public string productTrackingUrl { get; set; }
        public bool ninetySevenCentShipping { get; set; }
        public double standardShipRate { get; set; }
        public string size { get; set; }
        public string color { get; set; }
        public bool marketplace { get; set; }
        public bool shipToStore { get; set; }
        public bool freeShipToStore { get; set; }
        public string productUrl { get; set; }
        public string customerRating { get; set; }
        public int numReviews { get; set; }
        public string customerRatingImage { get; set; }
        public bool rollBack { get; set; }
        public bool bundle { get; set; }
        public bool clearance { get; set; }
        public string stock { get; set; }
        public string gender { get; set; }
        public string age { get; set; }
        public bool freeShippingOver50Dollars { get; set; }
        public bool availableOnline { get; set; }
    }
    [DataContract]
    public class RootObject
    {
        [DataMember]
        public List<Item> items { get; set; }
    }
}
示例Json记录:

Item_ID itemId  parentItemId    name    salePrice   upc shortDescription    longDescription brandName   thumbnailImage  mediumImage largeImage  productTrackingUrl  ninetySevenCentShipping standardShipRate    size    color   marketplace shipToStore freeShipToStore productUrl  customerRating  numReviews  customerRatingImage rollBack    bundle  clearance   stock   gender  age freeShippingOver50Dollars   availableOnline
 1  0   0   NULL    0   NULL    NULL    NULL    NULL    NULL    NULL    NULL    NULL    0   0   NULL    NULL    0   0   0   NULL    NULL    0   NULL    0   0   0   NULL    NULL    NULL    0   0
public API_Json_Special_Feeds.RootObject testExistingJson()
    {
        string json = "";
        //I saved a response to a text file so I don't overload the API with testing. The same problem happens whether or not I load from API or text file.
        using(TextReader tr = new StreamReader(@"C:jsonsingle.txt"))
        {
            json = tr.ReadToEnd();//string
        }
        var serializer = new DataContractJsonSerializer(typeof(API_Json_Special_Feeds.RootObject));

        var ms = new MemoryStream(Encoding.UTF8.GetBytes(json));
        var data = (API_Json_Special_Feeds.RootObject)serializer.ReadObject(ms);
         return data;
    }
 {"items":[ {
 "itemId" : 12321374,
 "parentItemId" : 12321374,
 "name" : "Castle Tent Loft Bed w/ Slide ; Under Bed Storage, Blue",
 "salePrice" : 369.0,
 "upc" : "081438383996",
 "shortDescription" : "Finished in White powder coat with Blue and Red Microfiber fabric tent",
 "longDescription" : "Fun Castle Tent Bunk Bed with Slide includes a tent over twin bed and a covered hiding place below. The covered hiding place below can also be used as under bed storage. The top of the slide is tented with a tower with peek through, fold down window covers. &lt;ul class=&quot;noindent&quot;&gt;&lt;li&gt;Finished in White powder coat with Blue and Red Microfiber fabric tent, 100% polyester.&lt;/li&gt;&lt;li&gt;Uses a standard twin size mattress (sold separately).&lt;/li&gt;&lt;li&gt;Only use a twin size mattress that is 74-75&quot; long and 37.5-38.5&quot; wide.&lt;/li&gt;&lt;li&gt;Bunk bed is tested and certified by an independent testing laboratory to meet all minimum requirements of ASTM F1427-07 and U.S. CFR 1213 and 1513.&lt;/li&gt;&lt;li&gt;Some assembly required. 79-3/4&quot; x 101-1/4&quot; x 92&quot; tall.&lt;/li&gt;&lt;/ul&gt;",
 "brandName" : "Castle",
 "thumbnailImage" : "https://i5.walmartimages.com/asr/a1bac83b-68f2-427e-82ac-97ce1e11b0c6_1.f18ff9fc14c7aca2d9c92c81f4b5c8ba.jpeg?odnHeight=100&odnWidth=100&odnBg=ffffff",
 "mediumImage" : "https://i5.walmartimages.com/asr/a1bac83b-68f2-427e-82ac-97ce1e11b0c6_1.f18ff9fc14c7aca2d9c92c81f4b5c8ba.jpeg?odnHeight=180&odnWidth=180&odnBg=ffffff",
 "largeImage" : "https://i5.walmartimages.com/asr/a1bac83b-68f2-427e-82ac-97ce1e11b0c6_1.f18ff9fc14c7aca2d9c92c81f4b5c8ba.jpeg?odnHeight=450&odnWidth=450&odnBg=ffffff",
 "productTrackingUrl" : "http://linksynergy.walmart.com/fs-bin/click?id=|LSNID|&offerid=223073.7200&type=14&catid=8&subid=0&hid=7200&tmpid=1082&RD_PARM1=http%253A%252F%252Fwww.walmart.com%252Fip%252FCastle-Tent-Loft-Bed-w-Slide--Under-Bed-Storage-Blue%252F12321374%253Faffp1%253D%257Capk%257C%2526affilsrc%253Dapi",
 "ninetySevenCentShipping" : false,
 "standardShipRate" : 0.0,
 "size" : "Twin",
 "color" : "Blue",
 "marketplace" : false,
 "shipToStore" : true,
 "freeShipToStore" : true,
 "productUrl" : "http://c.affil.walmart.com/t/api00rb?l=http%3A%2F%2Fwww.walmart.com%2Fip%2FCastle-Tent-Loft-Bed-w-Slide--Under-Bed-Storage-Blue%2F12321374%3Faffp1%3D%7Capk%7C%26affilsrc%3Dapi%26veh%3Daff%26wmlspartner%3Dreadonlyapi",
 "customerRating" : "4.574",
 "numReviews" : 54,
 "customerRatingImage" : "http://i2.walmartimages.com/i/CustRating/4_6.gif",
 "rollBack" : true,
 "bundle" : true,
 "clearance" : false,
 "stock" : "Available",
 "gender" : "Boys",
 "age" : "Child",
 "freeShippingOver50Dollars" : true,
 "availableOnline" : true
}]
}
public class API_Json_Special_Feeds
{
    [DataContract]
    public class Item
    {
        public int itemId { get; set; }
        public int parentItemId { get; set; }
        public string name { get; set; }
        public double salePrice { get; set; }
        public string upc { get; set; }
        public string shortDescription { get; set; }
        public string longDescription { get; set; }
        public string brandName { get; set; }
        public string thumbnailImage { get; set; }
        public string mediumImage { get; set; }
        public string largeImage { get; set; }
        public string productTrackingUrl { get; set; }
        public bool ninetySevenCentShipping { get; set; }
        public double standardShipRate { get; set; }
        public string size { get; set; }
        public string color { get; set; }
        public bool marketplace { get; set; }
        public bool shipToStore { get; set; }
        public bool freeShipToStore { get; set; }
        public string productUrl { get; set; }
        public string customerRating { get; set; }
        public int numReviews { get; set; }
        public string customerRatingImage { get; set; }
        public bool rollBack { get; set; }
        public bool bundle { get; set; }
        public bool clearance { get; set; }
        public string stock { get; set; }
        public string gender { get; set; }
        public string age { get; set; }
        public bool freeShippingOver50Dollars { get; set; }
        public bool availableOnline { get; set; }
    }
    [DataContract]
    public class RootObject
    {
        [DataMember]
        public List<Item> items { get; set; }
    }
}
Json类:

Item_ID itemId  parentItemId    name    salePrice   upc shortDescription    longDescription brandName   thumbnailImage  mediumImage largeImage  productTrackingUrl  ninetySevenCentShipping standardShipRate    size    color   marketplace shipToStore freeShipToStore productUrl  customerRating  numReviews  customerRatingImage rollBack    bundle  clearance   stock   gender  age freeShippingOver50Dollars   availableOnline
 1  0   0   NULL    0   NULL    NULL    NULL    NULL    NULL    NULL    NULL    NULL    0   0   NULL    NULL    0   0   0   NULL    NULL    0   NULL    0   0   0   NULL    NULL    NULL    0   0
public API_Json_Special_Feeds.RootObject testExistingJson()
    {
        string json = "";
        //I saved a response to a text file so I don't overload the API with testing. The same problem happens whether or not I load from API or text file.
        using(TextReader tr = new StreamReader(@"C:jsonsingle.txt"))
        {
            json = tr.ReadToEnd();//string
        }
        var serializer = new DataContractJsonSerializer(typeof(API_Json_Special_Feeds.RootObject));

        var ms = new MemoryStream(Encoding.UTF8.GetBytes(json));
        var data = (API_Json_Special_Feeds.RootObject)serializer.ReadObject(ms);
         return data;
    }
 {"items":[ {
 "itemId" : 12321374,
 "parentItemId" : 12321374,
 "name" : "Castle Tent Loft Bed w/ Slide ; Under Bed Storage, Blue",
 "salePrice" : 369.0,
 "upc" : "081438383996",
 "shortDescription" : "Finished in White powder coat with Blue and Red Microfiber fabric tent",
 "longDescription" : "Fun Castle Tent Bunk Bed with Slide includes a tent over twin bed and a covered hiding place below. The covered hiding place below can also be used as under bed storage. The top of the slide is tented with a tower with peek through, fold down window covers. &lt;ul class=&quot;noindent&quot;&gt;&lt;li&gt;Finished in White powder coat with Blue and Red Microfiber fabric tent, 100% polyester.&lt;/li&gt;&lt;li&gt;Uses a standard twin size mattress (sold separately).&lt;/li&gt;&lt;li&gt;Only use a twin size mattress that is 74-75&quot; long and 37.5-38.5&quot; wide.&lt;/li&gt;&lt;li&gt;Bunk bed is tested and certified by an independent testing laboratory to meet all minimum requirements of ASTM F1427-07 and U.S. CFR 1213 and 1513.&lt;/li&gt;&lt;li&gt;Some assembly required. 79-3/4&quot; x 101-1/4&quot; x 92&quot; tall.&lt;/li&gt;&lt;/ul&gt;",
 "brandName" : "Castle",
 "thumbnailImage" : "https://i5.walmartimages.com/asr/a1bac83b-68f2-427e-82ac-97ce1e11b0c6_1.f18ff9fc14c7aca2d9c92c81f4b5c8ba.jpeg?odnHeight=100&odnWidth=100&odnBg=ffffff",
 "mediumImage" : "https://i5.walmartimages.com/asr/a1bac83b-68f2-427e-82ac-97ce1e11b0c6_1.f18ff9fc14c7aca2d9c92c81f4b5c8ba.jpeg?odnHeight=180&odnWidth=180&odnBg=ffffff",
 "largeImage" : "https://i5.walmartimages.com/asr/a1bac83b-68f2-427e-82ac-97ce1e11b0c6_1.f18ff9fc14c7aca2d9c92c81f4b5c8ba.jpeg?odnHeight=450&odnWidth=450&odnBg=ffffff",
 "productTrackingUrl" : "http://linksynergy.walmart.com/fs-bin/click?id=|LSNID|&offerid=223073.7200&type=14&catid=8&subid=0&hid=7200&tmpid=1082&RD_PARM1=http%253A%252F%252Fwww.walmart.com%252Fip%252FCastle-Tent-Loft-Bed-w-Slide--Under-Bed-Storage-Blue%252F12321374%253Faffp1%253D%257Capk%257C%2526affilsrc%253Dapi",
 "ninetySevenCentShipping" : false,
 "standardShipRate" : 0.0,
 "size" : "Twin",
 "color" : "Blue",
 "marketplace" : false,
 "shipToStore" : true,
 "freeShipToStore" : true,
 "productUrl" : "http://c.affil.walmart.com/t/api00rb?l=http%3A%2F%2Fwww.walmart.com%2Fip%2FCastle-Tent-Loft-Bed-w-Slide--Under-Bed-Storage-Blue%2F12321374%3Faffp1%3D%7Capk%7C%26affilsrc%3Dapi%26veh%3Daff%26wmlspartner%3Dreadonlyapi",
 "customerRating" : "4.574",
 "numReviews" : 54,
 "customerRatingImage" : "http://i2.walmartimages.com/i/CustRating/4_6.gif",
 "rollBack" : true,
 "bundle" : true,
 "clearance" : false,
 "stock" : "Available",
 "gender" : "Boys",
 "age" : "Child",
 "freeShippingOver50Dollars" : true,
 "availableOnline" : true
}]
}
public class API_Json_Special_Feeds
{
    [DataContract]
    public class Item
    {
        public int itemId { get; set; }
        public int parentItemId { get; set; }
        public string name { get; set; }
        public double salePrice { get; set; }
        public string upc { get; set; }
        public string shortDescription { get; set; }
        public string longDescription { get; set; }
        public string brandName { get; set; }
        public string thumbnailImage { get; set; }
        public string mediumImage { get; set; }
        public string largeImage { get; set; }
        public string productTrackingUrl { get; set; }
        public bool ninetySevenCentShipping { get; set; }
        public double standardShipRate { get; set; }
        public string size { get; set; }
        public string color { get; set; }
        public bool marketplace { get; set; }
        public bool shipToStore { get; set; }
        public bool freeShipToStore { get; set; }
        public string productUrl { get; set; }
        public string customerRating { get; set; }
        public int numReviews { get; set; }
        public string customerRatingImage { get; set; }
        public bool rollBack { get; set; }
        public bool bundle { get; set; }
        public bool clearance { get; set; }
        public string stock { get; set; }
        public string gender { get; set; }
        public string age { get; set; }
        public bool freeShippingOver50Dollars { get; set; }
        public bool availableOnline { get; set; }
    }
    [DataContract]
    public class RootObject
    {
        [DataMember]
        public List<Item> items { get; set; }
    }
}
公共类API\u Json\u特殊\u提要
{
[数据合同]
公共类项目
{
公共int itemId{get;set;}
public int parentItemId{get;set;}
公共字符串名称{get;set;}
公共双价格{get;set;}
公共字符串upc{get;set;}
公共字符串shortDescription{get;set;}
公共字符串longDescription{get;set;}
公共字符串brandName{get;set;}
公共字符串thumbnailImage{get;set;}
公共字符串mediumImage{get;set;}
公共字符串大图像{get;set;}
公共字符串productTrackingUrl{get;set;}
public bool ninetySevenCentShipping{get;set;}
公共双标准费率{get;set;}
公共字符串大小{get;set;}
公共字符串颜色{get;set;}
公共布尔市场{get;set;}
公共bool shipToStore{get;set;}
公共bool freeShipToStore{get;set;}
公共字符串productUrl{get;set;}
公共字符串customerRating{get;set;}
public int numReviews{get;set;}
公共字符串customerRatingImage{get;set;}
公共布尔回滚{get;set;}
公共布尔包{get;set;}
公共布尔清除{get;set;}
公共字符串stock{get;set;}
公共字符串{get;set;}
公共字符串年龄{get;set;}
公共图书馆免费送货超过50美元{get;set;}
公共bool可用联机{get;set;}
}
[数据合同]
公共类根对象
{
[数据成员]
公共列表项{get;set;}
}
}
步骤1:

将JSON放到这个站点上,构建C#POCO模型()

步骤2:

从Newtonsoft获取Json.Net

步骤3:

RootObject myObject = JsonConvert.DeserializeObject<RootObject>(jsonString);
RootObject myObject=JsonConvert.DeserializeObject(jsonString);
简单地回到另一个方向:

string jsonString = JsonConvert.SerializeObject<RootObject>(myObject);
string jsonString=JsonConvert.SerializeObject(myObject);
步骤4:

请阅读所有关于Json.Net的内容,因为它在处理.Net中的Json方面远远优于其他任何东西。如果你喜欢冒险,如果你还没有尝试过,也可以阅读动态类型。Net和C#中的动态类型=做同样事情的代码要少得多

最后一件事。不需要任何属性,只需要有一个空构造函数,或者没有构造函数。

步骤1:

将JSON放到这个站点上,构建C#POCO模型()

步骤2:

从Newtonsoft获取Json.Net

步骤3:

RootObject myObject = JsonConvert.DeserializeObject<RootObject>(jsonString);
RootObject myObject=JsonConvert.DeserializeObject(jsonString);
简单地回到另一个方向:

string jsonString = JsonConvert.SerializeObject<RootObject>(myObject);
string jsonString=JsonConvert.SerializeObject(myObject);
步骤4:

请阅读所有关于Json.Net的内容,因为它在处理.Net中的Json方面远远优于其他任何东西。如果你喜欢冒险,如果你还没有尝试过,也可以阅读动态类型。Net和C#中的动态类型=做同样事情的代码要少得多


最后一件事。不需要任何属性,只需要有一个空构造函数,或者没有构造函数。

您应该将
[DataMember]
属性添加到Item类的属性中。
现在只“检测到”项目列表,项目对象用默认值序列化

您应该向项目类中的属性添加
[DataMember]
属性。
现在只有项目列表被“检测到”,项目对象用默认值序列化

Whoops!你说得对极了!全脑放屁。去换衣服……就是这样!我使用其中一个剪切粘贴站点来创建类,但出于某种原因,它没有添加属性。我太新了,没注意到有什么不同。但愿我三个小时前就发了帖子,而不是对这个问题大发雷霆。我真的很欣赏你的鹰眼!真棒的第一个答案!!哎呀!你说得对极了!全脑放屁。去换衣服……就是这样!我使用其中一个剪切粘贴站点来创建类,但出于某种原因,它没有添加属性。我太新了,没注意到有什么不同。但愿我三个小时前就发了帖子,而不是对这个问题大发雷霆。我真的很欣赏你的鹰眼!真棒的第一个答案!!我真的很感激。我将反序列化方法的最后一行更改为返回JsonConvert.DeserializeObject(json);仍然得到了0/null,但另一个答案表明我需要添加更多的datamembers。一旦我这么做了,我肯定会采纳你的建议。非常感谢!虽然我同意这一点