Silverlight 에 제 이 슨 을 Geometry 로 해석 하 는 방법 을 제공 합 니 다.
6866 단어 jsonString테스트nullsilverlight
SOE , Json , Silverlight , , , Json Silverlight Geometry , , 。
/// <summary>
/// json Geometry, M Z, , 。 ArcObjects Geometry json 。
/// :
/// 2012
/// </summary>
/// <param name="jsonResponse"></param>
/// <returns></returns>
private ESRI.ArcGIS.Client.Geometry.Geometry ParsefromJson(string jsonResponse)
{
JsonObject jsonObject = JsonObject.Parse(jsonResponse.ToString()) as JsonObject;
SpatialReference pSpatial = new SpatialReference();
ESRI.ArcGIS.Client.Geometry.Geometry pGeo = null;
if (jsonObject.ContainsKey("geometries"))
{
JsonObject jsonObjectGeo = jsonObject["geometries"] as JsonObject;
//
if (jsonObjectGeo.ContainsKey("spatialReference"))
{
pSpatial = this.myMap.SpatialReference;
//JsonObject pSpatialJson =jsonObjectGeo["spatialReference"] as JsonObject;
//
}
// , hasz hasM
if (jsonObjectGeo.ContainsKey("points"))
{
JsonValue JsonPoints = jsonObjectGeo["points"];
if (JsonPoints is JsonArray)
{
if (JsonPoints.Count == 1)
{
MapPoint pPoint = new MapPoint();
//
string[] pStrPoints = JsonPoints[0].ToString().Substring(1, JsonPoints[0].ToString().Length - 2).Split(',');
pPoint.X = Convert.ToDouble(pStrPoints[0]);
pPoint.Y = Convert.ToDouble(pStrPoints[1]);
pGeo = pPoint;
}
}
}
else if (jsonObjectGeo.ContainsKey("paths"))
{
JsonValue JsonPoints = jsonObjectGeo["paths"];
ESRI.ArcGIS.Client.Geometry.Polyline pPolyline = new ESRI.ArcGIS.Client.Geometry.Polyline();
ObservableCollection<ESRI.ArcGIS.Client.Geometry.PointCollection> pPointCollection = new ObservableCollection<ESRI.ArcGIS.Client.Geometry.PointCollection>();
// pPolyline.Paths
if (JsonPoints is JsonArray)
{
for (int i = 0; i < JsonPoints.Count; i++)
{
if (JsonPoints[i] is JsonArray)
{
ESRI.ArcGIS.Client.Geometry.PointCollection pPointCollections = new ESRI.ArcGIS.Client.Geometry.PointCollection();
JsonArray pInnerPoints = JsonPoints[i] as JsonArray;
for (int j = 0; j < pInnerPoints.Count; j++)
{
string pStr = pInnerPoints[j].ToString();
string[] pStrPoints = pInnerPoints[j].ToString().Substring(1, pInnerPoints[j].ToString().Length - 2).Split(',');
MapPoint pPoint = new MapPoint();
pPoint.X = Convert.ToDouble(pStrPoints[0]);
pPoint.Y = Convert.ToDouble(pStrPoints[1]);
pPointCollections.Add(pPoint);
}
pPointCollection.Add(pPointCollections);
}
}
pPolyline.Paths = pPointCollection;
pGeo = pPolyline;
}
}
else if (jsonObjectGeo.ContainsKey("rings"))
{
JsonValue JsonPoints = jsonObjectGeo["rings"];
ESRI.ArcGIS.Client.Geometry.Polygon pPolygon = new ESRI.ArcGIS.Client.Geometry.Polygon();
ObservableCollection<ESRI.ArcGIS.Client.Geometry.PointCollection> pPointCollection = new ObservableCollection<ESRI.ArcGIS.Client.Geometry.PointCollection>();
if (JsonPoints is JsonArray)
{
for (int i = 0; i < JsonPoints.Count; i++)
{
if (JsonPoints[i] is JsonArray)
{
ESRI.ArcGIS.Client.Geometry.PointCollection pPointCollections = new ESRI.ArcGIS.Client.Geometry.PointCollection();
JsonArray pInnerPoints = JsonPoints[i] as JsonArray;
for (int j = 0; j < pInnerPoints.Count; j++)
{
string pStr = pInnerPoints[j].ToString();
string[] pStrPoints = pInnerPoints[j].ToString().Substring(1, pInnerPoints[j].ToString().Length - 2).Split(',');
MapPoint pPoint = new MapPoint();
pPoint.X = Convert.ToDouble(pStrPoints[0]);
pPoint.Y = Convert.ToDouble(pStrPoints[1]);
pPointCollections.Add(pPoint);
}
pPointCollection.Add(pPointCollections);
}
}
pPolygon.Rings= pPointCollection;
pGeo = pPolygon;
}
}
}
pGeo.SpatialReference = pSpatial;
return pGeo;
}
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
콘텐츠 SaaS | JSON 스키마 양식 빌더Bloomreach Content를 위한 JSON Form Builder 맞춤형 통합을 개발합니다. 최근 Bloomreach Content SaaS는 내장 앱 프레임워크를 사용하여 혁신적인 콘텐츠 유형 필드를 구축할...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.