问题
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