想要反序列化豆瓣電台資料:
{"r":0,"song":[{"picture":"http:\/\/img1.douban.com\/mpic\/s1417892.jpg","albumtitle":"我不是黃蓉","company":"","rating_avg":3.19481,"public_time":"2004","ssid":"0283","album":"\/subject\/1408779\/","like":"0","artist":"王蓉","url":"http:\/\/mr3.douban.com\/201204261547\/54c99b0359802c774a9fd004d0dbcca3\/view\/song\/small\/p702236.mp3","title":"我不是黃蓉","subtype":"","length":217,"sid":"702236","aid":"1408779"},{"picture":"http:\/\/img1.douban.com\/mpic\/s1413751.jpg","albumtitle":"堅持到底","company":"","rating_avg":3.45544,"public_time":"2002","ssid":"ea36","album":"\/subject\/1404968\/","like":"0","artist":"阿杜","url":"http:\/\/mr3.douban.com\/201204261547\/61fd94ed3d09ac99c2adbc7979b6f0b1\/view\/song\/small\/p468095.mp3","title":"下次如果離開你","subtype":"","length":263,"sid":"468095","aid":"1404968"},{"picture":"http:\/\/img3.douban.com\/mpic\/s3839395.jpg","albumtitle":"似水流年","company":"","rating_avg":4.52431,"public_time":"2003","ssid":"6f05","album":"\/subject\/1408222\/","like":"0","artist":"李健","url":"http:\/\/mr3.douban.com\/201204261547\/3f0bcdeafa2bde09fd7e9b6dc5e13d5b\/view\/song\/small\/p696589.mp3","title":"紫羅蘭","subtype":"","length":276,"sid":"696589","aid":"1408222"},{"picture":"http:\/\/img1.douban.com\/mpic\/s2974583.jpg","albumtitle":"青睐","company":"","rating_avg":4.33157,"public_time":"1998","ssid":"c7ed","album":"\/subject\/1776536\/","like":"0","artist":"劉沁","url":"http:\/\/mr4.douban.com\/201204261547\/d9d559f442e7ddd531944d16b1f3cf85\/view\/song\/small\/p706174.mp3","title":"探望","subtype":"","length":254,"sid":"706174","aid":"1776536"},{"picture":"http:\/\/img1.douban.com\/mpic\/s1648854.jpg","albumtitle":"舞娘","company":"","rating_avg":3.6028,"public_time":"2006","ssid":"9d7a","album":"\/subject\/1777567\/","like":"0","artist":"蔡依林","url":"http:\/\/mr3.douban.com\/201204261547\/3bd4507fb10319bdf5d78c2f17271fe6\/view\/song\/small\/p626537.mp3","title":"舞娘","subtype":"","length":184,"sid":"626537","aid":"1777567"},{"picture":"http:\/\/img1.douban.com\/mpic\/s3673472.jpg","albumtitle":"Greatest Hits","company":"","rating_avg":4.12889,"public_time":"2004","ssid":"ada5","album":"\/subject\/1770175\/","like":"0","artist":"A-Teens","url":"http:\/\/mr3.douban.com\/201204261547\/ce48ab60ae6071463515f50fb80af9fb\/view\/song\/small\/p580439.mp3","title":"Can't Help Falling In Love","subtype":"","length":185,"sid":"580439","aid":"1770175"},{"picture":"http:\/\/img1.douban.com\/mpic\/s3440611.jpg","albumtitle":"Playing My Game","company":"","rating_avg":4.5791,"public_time":"2003","ssid":"8dea","album":"\/subject\/3346253\/","like":"0","artist":"Lene Marlin","url":"http:\/\/mr5.douban.com\/201204261547\/1211b87f7ee89232b446f6464bcfa978\/view\/song\/small\/p1516271.mp3","title":"Unforgivable Sinner","subtype":"","length":241,"sid":"1516271","aid":"3346253"},{"picture":"http:\/\/img3.douban.com\/mpic\/s1646146.jpg","albumtitle":"All Good Things","company":"","rating_avg":4.37042,"public_time":"2004","ssid":"f6dc","album":"\/subject\/1401415\/","like":"1","artist":"Sissel","url":"http:\/\/mr3.douban.com\/201204261547\/b64ddc092afe8602e5013822d541b366\/view\/song\/small\/p380437.mp3","title":"Should It Matter","subtype":"","length":303,"sid":"380437","aid":"1401415"},{"picture":"http:\/\/img3.douban.com\/mpic\/s3375098.jpg","albumtitle":"Christmas in My Hear...","company":"","rating_avg":4.42263,"public_time":"2007","ssid":"03ba","album":"\/subject\/3311456\/","like":"0","artist":"Sarah Connor","url":"http:\/\/mr3.douban.com\/201204261547\/28e2c2a4fc9667f3a7c77549f61bb197\/view\/song\/small\/p1528887.mp3","title":"Christmas in My Heart","subtype":"","length":288,"sid":"1528887","aid":"3311456"},{"picture":"http:\/\/img1.douban.com\/mpic\/s1931453.jpg","albumtitle":"The Simpsons: Songs ...","company":"","rating_avg":4.06341,"public_time":"2006","ssid":"a51a","album":"\/subject\/1928228\/","like":"0","artist":"Danny Elfman \/ Alf Clausen","url":"http:\/\/mr4.douban.com\/201204261547\/21c78d9c212b9774f49308ff1547c4b0\/view\/song\/small\/p522272.mp3","title":"Two Dozen And One Greyhounds (","subtype":"","length":121,"sid":"522272","aid":"1928228"}]}
時,出現錯誤:"應為來自命名空間“”的元素“root”。。遇到名稱為“”、命名空間為“”的“None”。"
再使用.NET 3.5反序列化JSON資料時,構造對應的類
class Songs
{
[DataMember]
public string r { get; set; }
[DataMember]
public playlist[] song { get; set; }
} 其中playlist是跟根據豆瓣的資料類型構造的類。
解決方法:除去資料中‘\’即可。