Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/81.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/json/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/sqlite/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
r转换为json,需要值null才能取消引号_R_Json_Http_Request_Jsonlite - Fatal编程技术网

r转换为json,需要值null才能取消引号

r转换为json,需要值null才能取消引号,r,json,http,request,jsonlite,R,Json,Http,Request,Jsonlite,我正在发送一个http请求,其中正文需要采用json格式。作为标准,似乎引用了null值。这会阻止http请求正常工作。当测试手动构建字符串并删除null值的引号时,http请求工作正常 问题: jsonlite可以处理从所有空值中去掉引号吗 我当前的代码: 此手动构造的字符串可用于: {"epic":"Stockholm","currency": null} 如图所示,您可能需要使用NA而不是null: library(jsonlite) x <- list(epic = "Sto

我正在发送一个http请求,其中正文需要采用json格式。作为标准,似乎引用了null值。这会阻止http请求正常工作。当测试手动构建字符串并删除null值的引号时,http请求工作正常

问题:

jsonlite可以处理从所有空值中去掉引号吗

我当前的代码:

此手动构造的字符串可用于:

{"epic":"Stockholm","currency": null} 
如图所示,您可能需要使用NA而不是null:

library(jsonlite)

x <- list(epic = "Stockholm", currency = NA)
json <- toJSON(x,  auto_unbox = TRUE, na = "null")

下面的工作原理解决了这个问题

似乎我的源数据需要指定值NULL而不是NULL,以及如何对值NULL进行编码的设置

library(jsonlite)

x <- list(epic = "Stockholm", currency = NULL)
json <- toJSON(x,  auto_unbox = TRUE, null = "null")
原始x没有NULL,它有一个字符串NULL。用于解释类null对象的jsonlite参数是jsonlite::toJSON中的null=参数。如果输入数据的字符串为null,则生成输入数据时会出现问题,而不是jsonlite。
library(jsonlite)

x <- list(epic = "Stockholm", currency = NA)
json <- toJSON(x,  auto_unbox = TRUE, na = "null")
library(jsonlite)

x <- list(epic = "Stockholm", currency = NULL)
json <- toJSON(x,  auto_unbox = TRUE, null = "null")