我正在尝试使用FSharp.Data中的JSON Provider http://fsharp.github.io/FSharp.Data/library/JsonProvider.html
var values: [(num1: Int, num2: Int)] = {
var values = [(num1: Int, num2: Int)]()
for i in 0..<10 {
values.append((num1: 0, num2: 0))
}
return values
}()
val BookOrderNow:JsonProvider&lt; ...&gt; .Root = {“问”:[ [ “0.00001605” 14636.67789781 ] [ “0.00001606” 73739.31116785 ] [ “0.00001607” 1342158.7102721 ]],“出价”:[ [ “0.00001593” 17805.17982312 ] [ “0.00001591” 71659.725 ] [ “0.00001590” 67600.19748428 ]],“isFrozen”:“0”,“seq”:29534867}
type BookOrder = JsonProvider<"../Documents/sample.json">
let commandType = "returnOrderBook"
let currencyPair = "BTC_NXT"
let depth = string 3
let polReq = "https://poloniex.com/public?" + "command=" + commandType + "¤cyPair=" + currencyPair + "&depth="
+ depth
let BookOrderNow = BookOrder.Load(polReq)
val it:decimal [] [] = [| [| 0.00001593M; 17805.17982312M |] [| 0.00001591M; 71659.725M |] [| 0.00001590M; 67600.19748428M |] |]
是否有一种获取输出的方法
[ “询问”, “出价”; “的isFrozen”; “SEQ”]
如果我确实从某个变量BookOrderNow.Bids
中的某个函数/方法中获得“出价”,那么就会出现类似函数(在此特定情况下)
varname
并返回BookOrderNow.Bids的值?
我的意思是,如果我们知道IN ADVANCE中JSON文件的内容,我们不需要这样做,但如果我们不这样做,......?最终我想把数据放在Deedle Frame / Series对象中
感谢您的任何建议。这是我第一次认真使用这个库
答案 0 :(得分:2)
BookOrderNow.JsonValue.Properties()
|> Seq.map fst
|> printfn "%A" //=> seq ["asks"; "bids"; "isFrozen"; "seq"]
let getJsonContent (x:BookOrder.Root) varname =
x.JsonValue.GetProperty varname
|> JsonExtensions.AsArray
|> Array.map
(JsonExtensions.AsArray >> Array.map (JsonExtensions.AsDecimal))
但是,根据@Matiasd的评论,
&#34;类型提供程序最适合于模式在运行时和编译代码的生命周期内保持稳定的情况。&#34;
谢谢你们两位