Asp.net mvc GeoJSON.NET与ASP.NET MVC中的谷歌地图
我正在尝试使用ASP.NET MVC5库创建geoJSON数据并将其加载到Google地图中,尽管我在某些地方做了一些错误的事情 使用GitHub站点上发布的示例代码,我的控制器如下所示:Asp.net mvc GeoJSON.NET与ASP.NET MVC中的谷歌地图,asp.net-mvc,json,google-maps,google-maps-api-3,geojson,Asp.net Mvc,Json,Google Maps,Google Maps Api 3,Geojson,我正在尝试使用ASP.NET MVC5库创建geoJSON数据并将其加载到Google地图中,尽管我在某些地方做了一些错误的事情 使用GitHub站点上发布的示例代码,我的控制器如下所示: public ActionResult GetGeoJson() { var point = new GeoJSON.Net.Geometry.Point( new GeoJSON.Net.Geometry.GeographicPosition(45.79012
public ActionResult GetGeoJson()
{
var point = new GeoJSON.Net.Geometry.Point(
new GeoJSON.Net.Geometry.GeographicPosition(45.79012, 15.94107));
var featureProperties = new Dictionary<string, object> { {"Name", "Foo"} };
var model = new GeoJSON.Net.Feature.Feature(point, featureProperties);
var serializedData = JsonConvert.SerializeObject(model, Formatting.Indented,
new JsonSerializerSettings
{
ContractResolver = new CamelCasePropertyNamesContractResolver(),
NullValueHandling = NullValueHandling.Ignore
});
return Json(serializedData, JsonRequestBehavior.AllowGet);
}
一位亲戚给了我答案。我需要从更改控制器中的返回
return Json(serializedData, JsonRequestBehavior.AllowGet);
到
因为JsonResult也在序列化序列化的数据
"{\r\n \"geometry\":
{\r\n \"coordinates\": [\r\n 15.94107,\r\n 45.79012\r\n ],
\r\n \"type\": \"Point\"\r\n },
\r\n \"properties\": {\r\n \"name\": \"Foo\"\r\n },
\r\n \"type\": \"Feature\"\r\n}"
return Json(serializedData, JsonRequestBehavior.AllowGet);
return Content(serializedData, "application/json");