Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/283.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 使用LINQ的JSON.NET和数组_C#_Linq_Json.net - Fatal编程技术网

C# 使用LINQ的JSON.NET和数组

C# 使用LINQ的JSON.NET和数组,c#,linq,json.net,C#,Linq,Json.net,我看了这个问题和答案,它接近我所需要的。关键的区别在于我需要解析一个x,y对数组,每个记录形成一行或多行。下面是我的输入示例 { "displayFieldName" : "FACILITYID", "fieldAliases" : { "FACILITYID" : "Facility Identifier", }, "geometryType" : "esriGeometryPolyline", "spatialReference" : { "wkid" : 4326 }, "f

我看了这个问题和答案,它接近我所需要的。关键的区别在于我需要解析一个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]
      ]
    ]
  }
}
]
}
(查看*&where=OBJECTID%3C20&f=pjson查看完整列表)

我需要做的是将[“features”][“geometry”][“path”]数组解析为由x,y对组成的行。下面是我获取所有路径的方式(每个“记录”一条路径,如features数组中的路径):

这为我提供了路径,从中我可以依次处理每个点阵列:

foreach (var eachPolylineInPath in allPaths)
{
  IEnumerable<Point> linePoints = from line in eachPolylineInPath.Children()
                                  select new Point(
                                                  (double) line[0],
                                                  (double) line[1],
                                                  double.NaN);
}
foreach(所有路径中的变量eachPolylineInPath)
{
IEnumerable linePoints=从每个polyLineInPath.Children()中的行开始
选择新点(
(双)行[0],
(双)行[1],
双倍(n),;
}
这就是我被卡住的地方。我正在尝试从JArray和LINQ-y语句进行各种类型转换,但不断得到空结果或无法访问JProperty子值的异常


希望有人已经处理过使用LINQ在JSON.NET中转换数组的问题,并且可以解释我一定犯了一个愚蠢的错误,或者我没有看到明显的答案。

看起来路径是一个点数组,所以假设您希望每个路径都有一个IEnumerable,您需要:

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

你搞定了-我错过了p[“路径”]上的孩子们(),所以我4个小时的真相搜索结束了。非常感谢你。
var allPaths = from p in jsonObject["features"].Children()["geometry"]
               select p["paths"].Children();