简体   繁体   English

如何将原始JSON字符串传递给DeployR WebAPI?

[英]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. 某些参数是简单的字符串,但其他参数是R脚本通过调用fromJSON进行转换的JSON字符串。

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. 当我将简单的字符串值传递给服务器时,它们很好,但是当我尝试将JSON格式的字符串传递给服务器时,脚本执行失败。 This script has been tested locally and using it via the R.Net library also works. 该脚本已经在本地进行了测试,并且可以通过R.Net库使用它。 Unfortunately R.Net does not suite our use case as we need multi threading. 不幸的是,R.Net不适合我们的用例,因为我们需要多线程。

Example: 例:

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

taskOptions.rinputs.Add(jsonString);

//Execute request ....

Where the JSON data looks like this JSON数据如下所示

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

And the R call failing is 和R电话失败是

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? 如何将JSON格式的原始字符串作为rinput传递给部署服务器?

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. 似乎“ rjson”包在DeployR中不能很好地发挥作用。

Using the package "jsonlite" resolved the issue. 使用软件包“ jsonlite”解决了该问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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