具有可选属性的JSON类型提供程序的数据样本 [英] Data sample for JSON type provider with optional property

查看:104
本文介绍了具有可选属性的JSON类型提供程序的数据样本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用JSON类型提供程序通过API访问StackOverflow/StackExchange数据.一项警告,效果很好. API有一个限制,由字段"backoff"发出信号,该字段包含您应该推迟直到下一个请求的秒数. 结果,我不能仅将JSON TP指向URL,因为默认情况下不存在退避字段.响应通常如下所示:

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!

推荐答案

JSON类型提供者具有属性SampleIsList,将其设置为true.
关于它的文档部分有解析Twitter流 JsonProvider ,请向下滚动,因为无法直接引用该部分.

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.

您的示例文件应如下图

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

这篇关于具有可选属性的JSON类型提供程序的数据样本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆