Rush Modules/JSON

2873 ワード

main(){
    println("rush go~")

    
   # json    json  
    println("json    json  [JSON.load(path)]")


    dictPath = "/Users/jax/Desktop/LXBundlexx/json.json"

    json = JSON.load(dictPath)


    println(json)
 

    println("name is -->" + json["name"])



 #strign  json  



   json_str = '{"menu": {
  "id": "file",
  "value": "File",
  "popup": {
    "menuitem": [
      {"value": "New", "onclick": "CreateNewDoc()"},
      {"value": "Open", "onclick": "OpenDoc()"},
      {"value": "Close", "onclick": "CloseDoc()"}
    ]
  }
}}'

  json_obj = JSON.parse(json_str)

  println("strign  json  [JSON.parse(string)]")

  println(json_obj)
  println("[json_obj.menuitem--------->]" + json_obj["menu"]["popup"]["menuitem"][0]["value"])
  # println("json_obj--------->menuitem" + json_obj["popup"]["menuitem"])


 #json     --》
 dict = json_obj["menu"]["popup"]["menuitem"][0]


 println("json     【JSON.save(path,dict)】")

 JSON.save("/Users/jax/Desktop/LXBundlexx/json2.json",dict)



#json   jsonstr

 dumpStr = JSON.dump(dict)

 println("dumpStr is ------>" + dumpStr)

//  ,  dumpStr    【Abort:  $#@!("com.apple.hwte.rush.exception.TypeError", "value", "Invalid cast: VMString --> VMNumber")】
println("dumpStr is ------>" + dumpStr["value"])

}





rush file.rush運転

result

rush go~
json    json  [JSON.load(path)]
{"address":{"city":    , "country":  , "street":    .}, "isNonProfit"::TRUE:, "links":[{"name":Google, "url":http://www.google.com}, {"name":Baidu, "url":http://www.baidu.com}, {"name":SoSo, "url":http://www.SoSo.com}], "name":BeJson, "page":88, "url":http://www.bejson.com}
name is -->BeJson
strign  json  [JSON.parse(string)]
{"menu":{"id":file, "popup":{"menuitem":[{"onclick":CreateNewDoc(), "value":New}, {"onclick":OpenDoc(), "value":Open}, {"onclick":CloseDoc(), "value":Close}]}, "value":File}}
[json_obj.menuitem--------->]New
json     【JSON.save(path,dict)】
dumpStr is ------>{"onclick":"CreateNewDoc()","value":"New"}
Executing : '/Users/jax/Desktop/a.rush' at line 62
Abort:  $#@!("com.apple.hwte.rush.exception.TypeError", "value", "Invalid cast: VMString --> VMNumber")
TESTdeMacBook-Air:Desktop jax$