如何过滤 JSON YQL 请求中的属性?

How to filter properties in JSON YQL request?

我正在使用 Yahoo 查询语言 (YQL) 从不支持 CORS 的 Web 服务中检索 JSON 并过滤每个响应对象的属性,以便响应中的每个对象 JSON 只包含我需要的属性。

从 Web 服务返回的 JSON 如下所示:

{
    "results": [
        {},
        {},
        ...
    ]
}

我的查询目前是这样的:

select results from json where url="..."

这个returnsresults属性数组。如何将 "select" 查询或命令的其他部分修改为 select 仅 results 数组中每个结果对象中的某些属性?我无法从 documentation.

中找到它

在您的情况下,您应该将查询设置为 "results.name, results.number"

让我们看一个请求占位符 JSON (https://jsonplaceholder.typicode.com/posts) 的示例:

[
  {
    "userId": 1,
    "id": 1,
    "title": "sunt aut facere repellat provident occaecati excepturi optio reprehenderit",
    "body": "quia et suscipit\nsuscipit recusandae consequuntur expedita et cum\nreprehenderit molestiae ut ut quas totam\nnostrum rerum est autem sunt rem eveniet architecto"
  },
  {
    "userId": 1,
    "id": 2,
    "title": "qui est esse",
    "body": "est rerum tempore vitae\nsequi sint nihil reprehenderit dolor beatae ea dolores neque\nfugiat blanditiis voluptate porro vel nihil molestiae ut reiciendis\nqui aperiam non debitis possimus qui neque nisi nulla"
  },
  ...
]

在此示例中,根是一个数组,我们可以使用此 YQL 查询过滤数组的每个对象所具有的属性:

select json.userId, json.title from json where url='https://jsonplaceholder.typicode.com/posts'

这给出了这个 JSON 响应:

      "results": {
       "json": [
        {
         "json": {
          "title": "sunt aut facere repellat provident occaecati excepturi optio reprehenderit",
          "userId": "1"
         }
        },
        .
        .
        .