JSONPath第一次出现;“采集者”;
我有一个json文件,如下所示:JSONPath第一次出现;“采集者”;,jsonpath,Jsonpath,我有一个json文件,如下所示: { "cards": [ { "artist": "Steve Argyle", "images": { "mtgimage": "http://mtgimage.com/set/pMPR/ponder.jpg" }, }, { "artist": "Mark Tedin", "images": { "gatherer": "http://ga
{
"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字符串就可以完成。