[英]Double value in Dictionary
I have this code to get two double from jSon: 我有这段代码可以从jSon获得两个加倍:
Dictionary<string, object> dict = this.GetDicFromInput();
Decimal tmpLat = (Decimal)dict["lat"];
Decimal tmpLon = (Decimal)dict["lon"];
This is GetDicFromInput
: 这是
GetDicFromInput
:
private Dictionary<string, object> GetDicFromInput()
{
string input = null;
input = "{\"lon\":34.806109,\"lat\":31.9599733}";
var json = new JavaScriptSerializer() { MaxJsonLength = int.MaxValue };
Dictionary<string, object> dict = (Dictionary<string, object>)json.DeserializeObject(input);
return dict;
}
And when I run it I get: 当我运行它时,我得到:
[NullReferenceException: Object reference not set to an instance of an object.]
BabySitter.Search.Page_Load(Object sender, EventArgs e) in \\psf\home\Documents\Visual Studio 2010\Projects\BabySitter\BabySitter\Search.aspx.cs:28
System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e) +14
System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e) +35
System.Web.UI.Control.OnLoad(EventArgs e) +91
System.Web.UI.Control.LoadRecursive() +74
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +2207
This is the fail line: 这是失败行:
Decimal tmpLat = (Decimal)dict["lat"];
Use the generic function to return the exact object type you are creating. 使用通用函数返回您要创建的确切对象类型。
public T Deserialize<T>(string input)
In this case, 在这种情况下,
Dictionary<string, object> dict = json.DeserializeObject<Dictionary<string, object>(input);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.