我正在做一個在Windows Phone中解析Json的示例。我正在使用Json.Net(json.codeplex.com/releases/view/78509)庫來解析響應字符串。但是在解析時遇到異常。異常是「無法將JSON數組反序列化爲類型'System.String'。我在下面發佈我的代碼。在Windows Phone中JSON解析返回異常
JSON響應我得到
[{ 「運行」: 「194分鐘」], 「評級」:7.6, 「流派」: 「戲劇」, 「浪漫」], 「rating」:「PG_13」,「語言」:[「英語」,「法語」,「德語」,「瑞典語」,「意大利語」,「俄語」],「標題」:「泰坦尼克號」,「filming_locations」: 「」詹姆斯卡梅隆「],」imdb_id「:」tt0120338「,」導演「:[」美國加利福尼亞州聖克拉麗塔「,」海報「:」http://ia.media-imdb.com/images/M/[email protected]@._V1._SY317_CR0,0,214,317_.jpg「,」imdb_url「:」http://www.imdb.com/title/tt0120338/「演員「:」Leonardo DiCaprio「Kate Winslet」Billy Zane「Kathy Bates」Frances Fisher「」Gloria Stuart「」Bill Paxton「 ,「伯納德山」,「大衛華納」,「維克「Garber」,「Jonathan Hyde」,「Suzy Amis」,「Lewis Abernathy」,「Nicholas Cascone」,「Anatoly M. Sagalevitch」],「plot_simple」:「一位十七歲貴族,期待與她母親的一位富有的求婚者在豪華的,命運多RMS的RMS上愛上了一位善良但貧窮的藝術家泰坦尼克號「,」年份「:1997,」country「:[」USA「],」type「:」M「,」release_date「:19980403,」also_known_as「:[」3D泰坦尼克號「]]]
而解析代碼是
private void ParseResult(string input)
{
var root = Newtonsoft.Json.JsonConvert.DeserializeObject<RootObject1[]>(input);// here getting the exception "Cannot deserialize JSON array into type 'System.String"
}
對象類是
public class RootObject1
{
public string runtime { get; set; }
public int rating { get; set; }
public string rated { get; set; }
public string title { get; set; }
public string poster { get; set; }
public string imdb_url { get; set; }
public string writers { get; set; }
public string imdb_id { get; set; }
}
感謝。
謝謝。現在解決了。 :) – Arun