简体   繁体   中英

How do I pass raw JSON strings to the DeployR WebAPI?

Scenario:

I have a set of inputs that I need to pass through to the deployr server. Certain parameters are simple strings but others are JSON strings that get converted by the R script by calling fromJSON.

Problem

When I pass the simple string values to the server they are fine but when I try pass a JSON formatted string to the server, the script execution fails. This script has been tested locally and using it via the R.Net library also works. Unfortunately R.Net does not suite our use case as we need multi threading.

Example:

var jsonString = RDataFactory.createString("jsonData",
File.ReadAllText("Data/jsonData.txt"));

taskOptions.rinputs.Add(jsonString);

//Execute request ....

Where the JSON data looks like this

//jsonData.txt
{"ID":77674,"Name":"My Company","CurrencySymbol":"R"}

And the R call failing is

deployrInput('{ "name": "jsonData", "default": "", "render": "character" } ')
mydata <- fromJSON(jsonData) #everything disintegrates

Question:

How do I pass a raw string that is JSON formatted as an rinput to the deployr server?

Please forgive me if it is something small, relatively new to all this and couldn't find anything helpful in the docs.

Thanks in advance!

Figured it out. Seems the "rjson" package doesn't play nicely with DeployR.

Using the package "jsonlite" resolved the issue.

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