Data sample for JSON type provider with optional property

蹲街弑〆低调 提交于 2019-12-23 09:19:48

问题


I am trying to use the JSON type provider to access StackOverflow / StackExchange data via the API. It works great, with one caveat. The API has a throttle, which is signaled by a field "backoff" that contains the number of seconds you are supposed to back off until your next request. As a result, I can't just point the JSON TP to the url, because by default the backoff field is not present. This is how the response typically looks:

  {
  "items": [
    {
      "has_synonyms": true,
      "user_id": 1144035,
      "is_moderator_only": false,
      "is_required": false,
      "count": 7054,
      "name": "sql"
    },
    {
      "has_synonyms": true,
      "user_id": 1144035,
      "is_moderator_only": false,
      "is_required": false,
      "count": 16,
      "name": "algorithm"
    }
  ],
  "has_more": true,
  "quota_max": 10000,
  "quota_remaining": 9693
}

I assumed what I needed to do was to supply a sample which contains both an example without backoff (as above), and one along the lines of this:

  "has_more": true,
  "quota_max": 10000,
  "quota_remaining": 9693,
  "backoff": 10
}

... so that I get a Backoff Option. However, I am not sure how to structure / prepare the sample to that effect. Help would be much appreciated!


回答1:


JSON Type Provider has a property SampleIsList, set it to true.
There is a documentation section Parsing Twitter stream about it, JsonProvider please scroll down as there is no way to reference the section directly.

Your sample file should look like this

[{
  ...
  "has_more": true,
  "quota_max": 10000,
  "quota_remaining": 9693
},{
  ...
  "has_more": true,
  "quota_max": 10000,
  "quota_remaining": 9693,
  "backoff": 10
}]


来源:https://stackoverflow.com/questions/28978716/data-sample-for-json-type-provider-with-optional-property

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!