Json类型提供程序:解析有效的Json失败

时间:2015-05-08 02:09:29

标签: json f# type-providers f#-data

我的REPL中有以下代码块

#r "../packages/FSharp.Data.2.2.1/lib/net40/FSharp.Data.dll"

open FSharp.Data

[<Literal>]
let uri = "http://www.google.com/finance/option_chain?q=AAPL&output=json"

type OptionChain = JsonProvider<uri>

当我运行它时,FSI正在返回

  

错误1类型提供程序'ProviderImplementation.JsonProvider'   报告错误:无法从中读取样本JSON   'http://www.google.com/finance/option_chain?q=AAPL&output=json':   从字符1开始的无效JSON,snippet =
  ---- {expiry:{y:2
  ----- json =
  ------ {expiry:{y:2015,m:5,d:8},expirations: [{y:2015,m:5,d:8},{y:2015,m:5,d:15},

根据另外两个网站,这个json是有效的。这是TP中的错误吗?

1 个答案:

答案 0 :(得分:2)

输出无效JSON,因为没有引用某些键。

{expiry:{y:2015,m:5,d:8},expirations:[{y:2015,m:5,d:8},{y:2015,m:5,d:15},{y:2015,m:5,d:22},{y:2015,m:5,d:29},{y:2015,m:6,d:5},{y:2015,m:6,d:12},{y:2015,m:6,d:19},{y:2015,m:6,d:26},{y:2015,m:7,d:17},{y:2015,m:8,d:21},{y:2015,m:10,d:16},{y:2016,m:1,d:15},{y:2017,m:1,d:20}],
 puts:[{cid:"43623726334021",s:"AAPL150508P00085000",e:"OPRA",p:"-",c:"-",b:"-",a:"-",oi:"-",vol:"-",strike:"85.00",expiry:"May 8, 2015"},
 ...