ABOUT ME

-

Today
-
Yesterday
-
Total
-
  • Fsharp.Data (F# Data) Json parsing example
    F# 2016. 10. 20. 00:50

    #1. set of properties


    { "a" : "apple", "b" : "banana", "c" : "cocoa" }

    open FSharp.Data
    open FSharp.Data.JsonExtensions
    
    [<entrypoint>]
    let main argv = 
        let json_txt= """{"a":"apple","b":"banana","c":"cocoa"}"""
        JsonValue.Parse(json_txt).Properties
        |> Array.iter(fun (key,value) -> printfn "%s:%s" key (value.AsString()))
        0 // return an integer exit code
    


    #2. array of values


    ["apple","banana","cocoa"]

    open FSharp.Data
    open FSharp.Data.JsonExtensions
    
    [<entrypoint>]
    let main argv = 
        let json_txt= """["apple","banana","cocoa"]"""
        JsonValue.Parse(json_txt).AsArray()
        |> Array.iter(fun value -> printfn "%s" (value.AsString()))
        0 // return an integer exit code
    


    #3. mixed array


    ["apple","banana",[1,2,3]]

    open FSharp.Data
    open FSharp.Data.JsonExtensions
    
    [<entrypoint>]
    let main argv = 
        let json_txt= """["apple","banana",[1,2,3]]"""
        let ary = JsonValue.Parse(json_txt).AsArray()
        printfn "%s" (ary.[0].AsString())
        printfn "%s" (ary.[1].AsString())
        (ary.[2]).AsArray()
        |> Array.iter(fun value -> printfn "%i" (value.AsInteger()))
        0 // return an integer exit code
    


    'F#' 카테고리의 다른 글

    파일 읽어서 배열에 담기  (0) 2017.01.25
    F# lock  (0) 2016.10.24
    F# 타이머 예제  (0) 2016.03.11
    F# Async Task 예제  (0) 2016.03.11
    F# 에서 쓰레드 사용하기 예제  (0) 2016.03.11
Designed by Tistory.