JSON字符串转换为JSON对象时错误
字符串内容如下:
{"resultcode":"200","reason":"Return Successd!","result":{"data":[{"MCC":"460","MNC":"0","LAC":"4530","CELL":"3578","LNG":"116.294564","LAT":"40.035972","O_LNG":"116.30064968533","O_LAT":"40.037236056858","PRECISION":"641","ADDRESS":"北京市海淀区上地西路"}]},"error_code":0}
我想把他转换为JSON对象,对象定义如下:
class IPObj
{
public string resultcode { get; set; }
public string reason { get; set; }
public Result result { get; set; }
public string error_code { get; set; }
}
class Result
{
public Data data { get; set; }
}
class Data
{
public string MCC { get; set; }
public string MNC { get; set; }
public string LAC { get; set; }
public string CELL { get; set; }
public string LNG { get; set; }
public string LAT { get; set; }
public string O_LNG { get; set; }
public string O_LAT { get; set; }
public string PRECISION { get; set; }
public string ADDRESS { get; set; }
}
转换代码:
var serializer = new JavaScriptSerializer();
IPObj ret = serializer.Deserialize<IPObj>(retValue);//retValue为最上方贴出来的内容
但是在转换时,出现反序列化错误,请问我该如何定义对象才可以转换成功啊?谢谢