我有一个这样的 JSON 对象:
{"photos":
{"page":1,
"pages":414,
"perpage":10,
"total":"4136",
"photo":[
{
"id":"13193333",
"owner":"picture owner",
"title":"picture title",
"lat":43.81919,
"lon":11.294719,
"url":"http:\\...."
},
{
"id":"13193383",
"owner":"picture owner",
"title":"picture title",
"lat":43.81919,
"lon":11.294719,
"url":"http:\\...."
},
... (other items of "photo" like the two above).......
]},
"stat":"ok"}
根据 JSONPath 规范,如果我想选择所有“标题”,我将使用:
$.photos.photo[*].title
现在,对于我的 JSON 数据中的每个不同属性,我需要以一般方式获取其 JSONPath 字符串(例如,我不需要完全“标题”的 JSONpath - 像$.photos.photo[1].title
- 但一般的 JSONpath - like $.photos.photo[*].title
)。
编辑:我会尝试更好地解释(对不起我的英语不好!),我想要做的是以这种方式获取与每个属性相关的 JSONPath:
JSON attribute: "photos"
JSONPath("photos") = $.photos
JSON attribute: "photo"
JSONPath("photo") = $.photos.photo[*]
JSON attribute: "title"
JSONPath("title") = $.photos.photo[*].title
等等...
如何用 JS 或 PHP 语言解决这个问题?谢谢!