문제

나는 이것을 보았다 Json.net을 사용하여 JSON 구문 분석 질문과 답변이 나에게 필요한 것과 가깝습니다.중요한 차이점은 레코드당 하나 이상의 줄을 형성하는 x,y 쌍의 배열을 구문 분석해야 한다는 것입니다.다음은 내 입력의 예입니다.

{
"displayFieldName" : "FACILITYID", 
"fieldAliases" : {
"FACILITYID" : "Facility Identifier", 
}, 
"geometryType" : "esriGeometryPolyline", 
"spatialReference" : {
  "wkid" : 4326
}, 
"features" : [
{
  "attributes" : {
    "FACILITYID" : "", 
    "OBJECTID" : 1, 
  }, 
  "geometry" : 
  {
    "paths" : 
    [
      [
        [-80.3538239379999, 27.386884271], 
        [-80.3538100319999, 27.3868901900001], 
        [-80.3538157239999, 27.3869008510001]
      ]
    ]
  }
}, 
{
  "attributes" : {
    "FACILITYID" : "", 
    "OBJECTID" : 2, 
  }, 
  "geometry" : 
  {
    "paths" : 
    [
      [
        [-80.3538239379999, 27.386884271], 
        [-80.3538295849999, 27.3868948420001]
      ]
    ]
  }
}
]
}

(체크아웃 http://sampleserver1.arcgisonline.com/ArcGIS/rest/services/WaterTemplate/WaterDistributionNetwork/MapServer/9/query?outFields=*&where=OBJECTID%3C20&f=pjson 전체 목록 보기)

내가 해야 할 일은 ["features"]["geometry"]["paths"] 배열을 x,y 쌍으로 구성된 줄로 구문 분석하는 것입니다.모든 경로를 얻는 방법은 다음과 같습니다(기능 배열에서 "레코드"당 하나씩).

var allPaths = from p in jsonObject["features"].Children()["geometry"]
               select p["paths"];

그러면 각 포인트 배열을 차례로 처리할 수 있는 경로가 제공됩니다.

foreach (var eachPolylineInPath in allPaths)
{
  IEnumerable<Point> linePoints = from line in eachPolylineInPath.Children()
                                  select new Point(
                                                  (double) line[0],
                                                  (double) line[1],
                                                  double.NaN);
}

그것이 내가 붙어있는 곳입니다.JArray 및 LINQ-y 문에서 다양한 캐스트를 시도하고 있지만 계속 null 결과가 나오거나 JProperty 하위 값 조정에 대한 예외가 액세스할 수 없습니다.

누군가가 이미 LINQ를 사용하여 JSON.NET에서 배열 배열을 변환하는 작업을 처리했으며 제가 저지르고 있는 어리석은 실수나 제가 보지 못한 명백한 대답을 설명할 수 있기를 바랍니다.

도움이 되었습니까?

해결책

경로는 포인트 배열의 배열인 것처럼 보이므로 각 경로에 대해 IEnumerable을 원한다고 가정하면 다음이 필요합니다.

var allPaths = from p in jsonObject["features"].Children()["geometry"]
               select p["paths"].Children();
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top