在itemPath中使用哪条路径?

时间:2011-06-17 21:45:15

标签: yql

创建YQL表时,必须在表的元素中指定 itemPath 。根据{{​​3}},此itemPath应包含:

  

指向响应格式中重复数据元素出现位置的点路径。这些是你桌子的“行”。

如果我像这样指定 itemPath 那么我会在某些情况下“松散”某些数据。例如在下面的示例中,我将松开以下键/值对:

  • response => perpage,total,last_offset,page,window,offset,hidden
  • request =>所有键/值对丢失

这些键中的一些可能不那么有趣,因为它们仅用于分页,但我可能仍然对它们中的一些感兴趣,例如

所以我的问题是:

我是否应该在这种情况下指定itemPath json.response,它会给我整个回复,或者我应该指定json.response.list哪个只给我列表中的项目但是我必须接受松散一些数据?

实施例

YQL documentation

你会得到这样的回复:

{"response"=>
  {"list"=>
    [{"topsy_author_url"=>"http://topsy.com/twitter/al3xandru",
      "hits"=>819,
      "name"=>"Alex Popescu",
      "nick"=>"al3xandru",
      "url"=>"http://twitter.com/al3xandru",
      "photo_url"=>
       "http://a2.twimg.com/profile_images/1260935149/carmel_head_sk_sm_normal.jpg",
      "influence_level"=>"10",
      "description"=>
       "Founder/CTO InfoQ.com, Software architect, Web aficionado, Speaker, NOSQL Dreamer http://nosql.mypopescu.com"},
     {"topsy_author_url"=>"http://topsy.com/twitter/rgaidot",
      "hits"=>957,
      "name"=>"R\303\251gis Gaidot",
      "nick"=>"rgaidot",
      "url"=>"http://twitter.com/rgaidot",
      "photo_url"=>
       "http://a1.twimg.com/profile_images/1266738841/avatar-6_normal.jpg",
      "influence_level"=>"10",
      "description"=>"digital/technology enthusiast"},
     ...],
   "perpage"=>15,
   "total"=>113105,
   "last_offset"=>18,
   "page"=>1,
   "window"=>"a",
   "offset"=>0,
   "hidden"=>1},
 "request"=>
  {"response_type"=>"json",
   "resource"=>"experts",
   "parameters"=>{"q"=>"nosql"},
   "url"=>"http://otter.topsy.com/experts.json?q=nosql"}}

1 个答案:

答案 0 :(得分:1)

您选择用于表的itemPath取决于表的使用方式。如果只需要response.list信息,请将其设置为itemPath。如果request或非list信息有时会有用,那么请扩大路径。

可以选择向表中添加一个参数,以允许使用者像其他表一样指定itemPath,并将其默认为最常见的用例。或者,该表可以允许查询中的某些标志指示是仅返回结果列表还是整个原始响应。

就个人而言,我可能会选择json.response.list