请帮忙!在反序列化时出现此错误:
无法将“System.String”类型的对象转换为“System.Collections.Generic.List”类型
来自客户端的 JSON 字符串:
"\"[{\\"id\\":\\"18_0_2_0\\",\\"ans\\":\\"您可以输入自由文本代替 * \\"},{\\" id\\":\\"23_1_3_1\\",\\"ans\\":\\"刷新按钮\\"},{\\"id\\":\\"11_2_1_2\\",\ \"ans\\":\\"假\\"}]\""
编辑:未转义(见评论):
[{"id":"18_0_2_0","ans":"您可以输入自由文本代替* "},{"id":"11_2_1_2","ans":"False"}]
JavaScriptSerializer serializer = new JavaScriptSerializer();
List<RawAnswer> ListAnswers = serializer.Deserialize<List<RawAnswer>>(str);
[Serializable]
public class RawAnswer
{
public string QuestionID { get; set; }
public string Answer { get; set; }
public RawAnswer() { }
}
public class AnswerList
{
public List<RawAnswer> RawAnswer { get; set; }
}