美文网首页
Rush Modules/JSON

Rush Modules/JSON

作者: 拥抱月亮的大星星 | 来源:发表于2019-04-08 15:59 被阅读0次
    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$ 
    
    
    

    相关文章

      网友评论

          本文标题:Rush Modules/JSON

          本文链接:https://www.haomeiwen.com/subject/pbcpiqtx.html