【发布时间】:2013-05-11 00:55:50
【问题描述】:
我正在为 Windows Phone 中的 Json 解析做一个示例。我正在使用 Json.Net (json.codeplex.com/releases/view/78509) 库来解析响应字符串。但是在解析时出现异常。例外是“无法将 JSON 数组反序列化为“System.String”类型。我在下面发布我的代码。
我收到的 JSON 响应
[{"runtime": ["194 min"], "rating": 7.6, "genres": ["Drama", "Romance"], "rated": "PG_13", "language": ["英语”、“法语”、“德语”、“瑞典语”、“意大利语”、“俄语”]、“标题”:“泰坦尼克号”、“filming_locations”:“美国加利福尼亚州圣克拉丽塔”、“海报”:“ http://ia.media-imdb.com/images/M/MV5BMjExNzM0NDM0N15BMl5BanBnXkFtZTcwMzkxOTUwNw@@._V1._SY317_CR0,0,214,317_.jpg", "imdb_url": "http://www.imdb.com/title/tt0120338/", "writers": ["James Cameron"], "imdb_id": "tt0120338", "directors": ["James Cameron"], "rating_count": 426376 、“演员”:[“莱昂纳多·迪卡普里奥”、“凯特·温斯莱特”、“比利·赞恩”、“凯西·贝茨”、“弗朗西斯·费舍尔”、“格洛丽亚·斯图尔特”、“比尔·帕克斯顿”、“伯纳德·希尔”、“大卫·华纳” , "Victor Garber", "Jonathan Hyde", "Suzy Amis", "Lewis Abernathy", "Nicholas Cascone", "Anatoly M. Sagalevitch"], "plot_simple": "一个十七岁的贵族,期望成为由她的母亲嫁给了一个富有的索赔人,在豪华、命运多舛的泰坦尼克号上爱上了一位善良但贫穷的艺术家。”,“年份”:1997,“国家”:[“美国”],“类型”: “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; }
}
谢谢。
【问题讨论】:
标签: c# json windows-phone json.net