我在反序列化从Shodan获得的数据时遇到了问题。下面是我从json2csharp获得的类,我正在尝试创建一个匹配数组并遍历它们。似乎我已经尝试了所有的东西,除了一个工作数组。数据本身与包含位置(有自己的数据等)的对象作为根匹配。A除了下面我删掉了一点。这是我的错误:不能将当前JSON对象(例如,{“名称”:“值”})反序列化为'Shodan.Match[]‘类型,因为类型需要一个JSON数组(例如,1,2,3)来正确反序列化。
var data = JsonConvert.DeserializeObject<Match[]>(allData);
{"matches": [{"product": "product", "hash": 0, "ip": 123123, "isp": "Verizon Internet Services"}], "total": 1}
public class Location
{
public string city { get; set; }
public string region_code { get; set; }
public object area_code { get; set; }
public double longitude { get; set; }
public string country_code3 { get; set; }
public double latitude { get; set; }
public string postal_code { get; set; }
public object dma_code { get; set; }
public string country_code { get; set; }
public string country_name { get; set; }
}
public class Options
{
}
public class Shodan
{
public string crawler { get; set; }
public string id { get; set; }
public string module { get; set; }
public Options options { get; set; }
}
public class Match
{
public int hash { get; set; }
public int ip { get; set; }
public string isp { get; set; }
public string transport { get; set; }
public string data { get; set; }
public string asn { get; set; }
public int port { get; set; }
public List<string> hostnames { get; set; }
public Location location { get; set; }
public DateTime timestamp { get; set; }
public List<string> domains { get; set; }
public string org { get; set; }
public object os { get; set; }
public Shodan _shodan { get; set; }
public string ip_str { get; set; }
public string product { get; set; }
}
public class RootObject
{
public List<Match> matches { get; set; }
public int total { get; set; }
}发布于 2018-10-18 02:40:19
您可以创建另一个类,如
var allData =
{"matches": [{"product": "product", "hash": 0, "ip": 123123, "isp": "Verizon Internet Services"}], "total": 1}
public class MyMatches {
public Match[] matches {get; set;}
}然后在反序列化器中使用。var data = JsonConvert.DeserializeObject<MyMatches>(allData);
这是如果您提供的JSON代码示例是正确的话。
校正
刚看了RootObject的课程。用这个就行了。
https://stackoverflow.com/questions/52866135
复制相似问题