June 2018 Update

This commit is contained in:
Ingy döt Net 2018-06-22 20:57:24 +00:00
parent ba8067c3b7
commit 22f33d4004
5278 changed files with 84726 additions and 14379 deletions

View file

@ -1,5 +1,5 @@
Load a [[wp:JSON|JSON]] string into a data structure.
Also create a new data structure and serialize it into JSON.
Also, create a new data structure and serialize it into JSON.
Use objects and arrays (as appropriate for your language)
and make sure your JSON is valid (http://www.jsonlint.com/ or https://jsonformatter-online.com/).
and make sure your JSON is valid (https://jsonformatter.org or https://codebeautify.org/jsonvalidator).

View file

@ -1,7 +1,13 @@
julia> import JSON
# Pkg.add("JSON") ... an external library http://docs.julialang.org/en/latest/packages/packagelist/
using JSON
julia> JSON.parse("""{ "blue": [1,2], "ocean": "water" }""")
["ocean"=>"water","blue"=>{1,2}]
sample = Dict()
sample["blue"] = [1, 2]
sample["ocean"] = "water"
julia> JSON.json({"blue" => [1,2] , "ocean" => "water"})
"{\"ocean\":\"water\",\"blue\":[1,2]}"
@show sample jsonstring = json(sample)
@show jsonobj = JSON.parse(jsonstring)
@assert jsonstring == "{\"ocean\":\"water\",\"blue\":[1,2]}"
@assert jsonobj == Dict("ocean" => "water", "blue" => [1, 2])
@assert typeof(jsonobj) == Dict{String, Any}

View file

@ -0,0 +1,15 @@
// version 1.2.21
data class JsonObject(val foo: Int, val bar: Array<String>)
data class JsonObject2(val ocean: String, val blue: Array<Int>)
fun main(args: Array<String>) {
// JSON to object
val data: JsonObject = JSON.parse("""{ "foo": 1, "bar": ["10", "apples"] }""")
println(JSON.stringify(data))
// object to JSON
val data2 = JsonObject2("water", arrayOf(1, 2))
println(JSON.stringify(data2))
}