Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/url/2.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
JSONPath第一次出现;“采集者”;_Jsonpath - Fatal编程技术网

JSONPath第一次出现;“采集者”;

JSONPath第一次出现;“采集者”;,jsonpath,Jsonpath,我有一个json文件,如下所示: { "cards": [ { "artist": "Steve Argyle", "images": { "mtgimage": "http://mtgimage.com/set/pMPR/ponder.jpg" }, }, { "artist": "Mark Tedin", "images": { "gatherer": "http://ga

我有一个json文件,如下所示:

{
  "cards": [
    {
      "artist": "Steve Argyle",
      "images": {
        "mtgimage": "http://mtgimage.com/set/pMPR/ponder.jpg"
      },
    },
    {
      "artist": "Mark Tedin",
      "images": {
        "gatherer": "http://gatherer.wizards.com/Handlers/Image.ashx?type=card&multiverseid=139512",
        "mtgimage": "http://mtgimage.com/set/LRW/ponder.jpg"
      },
    },
    {
      "artist": "Dan Scott",
      "images": {
        "gatherer": "http://gatherer.wizards.com/Handlers/Image.ashx?type=card&multiverseid=190159",
        "mtgimage": "http://mtgimage.com/set/M10/ponder.jpg"
      },
    }
  ]
}
我想使用JSONPath从中获得第一个“gatherer”链接。 我尝试了“$…gatherer[0]”,但不起作用。但是“$…gatherer”确实给出了这两个实例:

[
   "http:\/\/gatherer.wizards.com\/Handlers\/Image.ashx?type=card&multiverseid=139512",
   "http:\/\/gatherer.wizards.com\/Handlers\/Image.ashx?type=card&multiverseid=190159"
]
我怎样才能得到第一个呢?(不获取代码中的最后一个,因此仅使用jsonpath字符串。)


(使用和在我的程序中测试。)

您可能需要临时步骤来保存阵列

var gatherers = $..gatherer;  //however this gets it, I'm not sure
var first = gatherers[0];

这可能有效。

您可能需要临时步骤来保存阵列

var gatherers = $..gatherer;  //however this gets it, I'm not sure
var first = gatherers[0];

那可能行得通。

那应该行得通。然而,我正在寻找一个只支持jsonpath的解决方案。其思想是用户可以输入自己的jsonpath字符串。获取第一个“gatherer”链接是我希望需要用到的东西。因此,我希望找到一种不需要代码的解决方案,并且只需要一个jsonpath字符串就可以完成。这确实应该是可行的。然而,我正在寻找一个只支持jsonpath的解决方案。其思想是用户可以输入自己的jsonpath字符串。获取第一个“gatherer”链接是我希望需要用到的东西。所以我希望找到一个不需要代码的解决方案,并且只需要一个jsonpath字符串就可以完成。