简体   繁体   中英

Python code to R

I need to replicate following Python code in R:

payloadObject = {
        'request':'/v1/balances',
        'nonce':str(1417217972400792), 
        'options':{}
}
payload_json = json.dumps(payloadObject)
payload = base64.b64encode(bytes(payload_json, "utf-8"))

and so far I have

require("RJSONIO")

payloadObject <- list(request = "/v1/balances", nonce = "1417217972400792", options = {})
payload_json <- toJSON(payloadObject)

Can you help with the last line payload = base64.b64encode(bytes(payload_json, "utf-8"))?

RCurl has base64 that you can use for the last part. I also used jsonlite vs RJSONIO (latter is a more modern fork):

library(RCurl)
library(jsonlite)

payloadObject <- list(request = "/v1/balances", 
                      nonce = "1417217972400792", 
                      options = {})
payload_json <- toJSON(payloadObject)
payload <- base64(payload_json)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM