从淘宝IP地址库取出来的json数据,在C#中用了newtonsoft.Json进行反序列,新建一个信息类Root
///
/// 210.75.225.254
///
public string ip { get; set; }
///
/// 中国
///
public string country { get; set; }
///
/// 华北
///
public string area { get; set; }
///
/// 北京市
///
public string region { get; set; }
///
/// 北京市
///
public string city { get; set; }
///
///
///
public string county { get; set; }
///
/// 电信
///
public string isp { get; set; }
///
/// 86
///
public string country_id { get; set; }
///
/// 100000
///
public string area_id { get; set; }
///
/// 110000
///
public string region_id { get; set; }
///
/// 110000
///
public string city_id { get; set; }
///
/// -1
///
public string county_id { get; set; }
///
/// 100017
///
public string isp_id { get; set; }
}
public class Root
{
/// <summary>
/// Code
/// </summary>
public int code { get; set; }
/// <summary>
/// Data
/// </summary>
public Data data { get; set; }
}
关键代码
List<Root> _list = JsonConvert.DeserializeObject<List<Root>>(result);
foreach (Root c in _list)
{
Console.WriteLine(c.code);
}
但一直报错,如图,求教,万分感谢。

图片就是说反序列错误
只返回一个JSON对象把,是集合?你用的什么接口
http://ip.taobao.com/service/getIpInfo2.php只返回单个,不是类集合
Root _list = JsonConvert.DeserializeObject<Root>(result);