数组反序列化不支持获取错误类型 'System.String'
Getting error Type 'System.String' is not supported for deserialization of an array
我在使用 JavascriptDeserializer
在 c# 中反序列化 JSON 对象的嵌套数组时遇到问题
这是我的代码
using (Stream s = request.GetResponse().GetResponseStream())
{
using (StreamReader sr = new StreamReader(s))
{
string jsondata = sr.ReadToEnd();
var workout = ser.Deserialize<clServiceOutput1>(jsondata);
}
}
这是我的 Jsondata
{"Data":"50951","FileData":[37,80,68,70,45,49,46,51,13,37,226,227,207,211,13,10],"MailItem":null,"Status":"Success","TurnAroundTime":null}
这是我的 class
public class clServiceOutput1
{
public string Data { get; set; }
public string FileData { get; set; }
public string MailItem { get; set; }
public string Status { get; set; }
public string TurnAroundTime { get; set; }
}
FileData
是 json
字符串中数值的集合。
"FileData":[37,80,68,70,45,49,46,51,13,37,226,227,207,211,13,10]
你需要
List<int> FileData //or int[]
作为旁注,使用 http://json2csharp.com/ 复制您的 json 并取回 C# 模板 class。将您的 JSON 粘贴到上述站点会导致:
public class RootObject
{
public string Data { get; set; }
public List<int> FileData { get; set; }
public object MailItem { get; set; }
public string Status { get; set; }
public object TurnAroundTime { get; set; }
}
基于 @xanatos
的评论
By the name of the field, it seems to be the binary "stream" of a
file, not something that must be expanded. So a byte[]
could also
be the type of your field
我在使用 JavascriptDeserializer
在 c# 中反序列化 JSON 对象的嵌套数组时遇到问题这是我的代码
using (Stream s = request.GetResponse().GetResponseStream())
{
using (StreamReader sr = new StreamReader(s))
{
string jsondata = sr.ReadToEnd();
var workout = ser.Deserialize<clServiceOutput1>(jsondata);
}
}
这是我的 Jsondata
{"Data":"50951","FileData":[37,80,68,70,45,49,46,51,13,37,226,227,207,211,13,10],"MailItem":null,"Status":"Success","TurnAroundTime":null}
这是我的 class
public class clServiceOutput1
{
public string Data { get; set; }
public string FileData { get; set; }
public string MailItem { get; set; }
public string Status { get; set; }
public string TurnAroundTime { get; set; }
}
FileData
是 json
字符串中数值的集合。
"FileData":[37,80,68,70,45,49,46,51,13,37,226,227,207,211,13,10]
你需要
List<int> FileData //or int[]
作为旁注,使用 http://json2csharp.com/ 复制您的 json 并取回 C# 模板 class。将您的 JSON 粘贴到上述站点会导致:
public class RootObject
{
public string Data { get; set; }
public List<int> FileData { get; set; }
public object MailItem { get; set; }
public string Status { get; set; }
public object TurnAroundTime { get; set; }
}
基于 @xanatos
的评论By the name of the field, it seems to be the binary "stream" of a file, not something that must be expanded. So a
byte[]
could also be the type of your field