Json Parse Error: Illegal unquoted character ((CTRL-CHAR, code 10) - (httr:: POST in R)

Json Parse Error: Illegal unquoted character ((CTRL-CHAR, code 10) - (httr:: POST in R)

这是我的全部代码,当 运行 我收到以下错误:

 JSON parse error: Illegal unquoted character ((CTRL-CHAR, code 10)): has to be escaped using backslash to be included in string value\n at [Source: (PushbackInputStream); line: 2, column: 4096]; nested exception is com.fasterxml.jackson.databind.JsonMappingException: Illegal unquoted character ((CTRL-CHAR, code 10)): has to be escaped using backslash to be included in string value\n at [Source: (PushbackInputStream); line: 2, column: 4096]\n at [Source: (PushbackInputStream); line: 2, column: 15] (through reference chain: com.apc.its.services.tsdb.server.common.model.request.TsdbRequest["tagCsv"]




library(httr)
library(jsonlite)
library(data.table)
library(dplyr)
library(tidyr)

url <- "someURL"
params <- list()
params <- '{
    "tagCsv": "LU_HIST_SVR.E919_5_ChokeActiveFirstScan,(0*LU_HIST_SVR.GSLuCPR01_ActiveHHSP)+2930,(0*LU_HIST_SVR.GSLuCPR01_ActiveHHSP)+3371,(0*LU_HIST_SVR.GSLuCPR02_ActiveHHSP)+2930,(0*LU_HIST_SVR.GSLuCPR02_ActiveHHSP)+3371,(0*LU_HIST_SVR.GSLuCPR03_ActiveHHSP)+2930,(0*LU_HIST_SVR.GSLuCPR03_ActiveHHSP)+3371,(0*LU_HIST_SVR.GSLuCPR04_ActiveHHSP)+2930,(0*LU_HIST_SVR.GSLuCPR04_ActiveHHSP)+3371,(-LU_HIST_SVR.GSLuCPR01_ActiveHHSP),(-LU_HIST_SVR.GSLuCPR02_ActiveHHSP),(-LU_HIST_SVR.GSLuCPR03_ActiveHHSP),(-LU_HIST_SVR.GSLuCPR04_ActiveHHSP),(-LU_HIST_SVR.SS_KC874_1_PPD_R + LU_HIST_SVR.SS_KC874_1_PPU_R),(-LU_HIST_SVR.SS_KC875_1_PPD_R + LU_HIST_SVR.SS_KC875_1_PPU_R),(-LU_HIST_SVR.SS_KC875_3_PPD_R + LU_HIST_SVR.SS_KC875_3_PPU_R),(-LU_HIST_SVR.SS_KC875_4_PPD_R + LU_HIST_SVR.SS_KC875_4_PPU_R),(-LU_HIST_SVR.SS_KC875_5_PPD_R + LU_HIST_SVR.SS_KC875_5_PPU_R),(-LU_HIST_SVR.SS_KC918_1_PPD_R + LU_HIST_SVR.SS_KC918_1_PPU_R),(-LU_HIST_SVR.SS_KC919_3_PPD_R + LU_HIST_SVR.SS_KC919_3_PPU_R),(-LU_HIST_SVR.SS_KC919_5_PPD_R + LU_HIST_SVR.SS_KC919_5_PPU_R),(-LU_HIST_SVR.SS_KC919_6_PPD_R + LU_HIST_SVR.SS_KC919_6_PPU_R),(-LU_HIST_SVR.SS_KC919_7_PPD_R + LU_HIST_SVR.SS_KC919_7_PPU_R),(-LU_HIST_SVR.SS_KC919_8_PPD_R + LU_HIST_SVR.SS_KC919_8_PPU_R),DNE,LU_HIST_SVR.C874_1_DPTSlope,LU_HIST_SVR.C874_1_DPTSteadyState + LU_HIST_SVR.C874_1_DPTTransientState + LU_HIST_SVR.C874_1_DPTShutInState,LU_HIST_SVR.C874_1_DPTTransSlope,LU_HIST_SVR.C875_1_DPTSlope,LU_HIST_SVR.C875_1_DPTSteadyState + LU_HIST_SVR.C875_1_DPTTransientState + LU_HIST_SVR.C875_1_DPTShutInState,LU_HIST_SVR.C875_1_DPTTransSlope,LU_HIST_SVR.C875_3_DPTSlope,LU_HIST_SVR.C875_3_DPTSteadyState + LU_HIST_SVR.C875_3_DPTTransientState + LU_HIST_SVR.C875_3_DPTShutInState,LU_HIST_SVR.C875_3_DPTTransSlope,LU_HIST_SVR.C875_4_DPTSlope,LU_HIST_SVR.C875_4_DPTSteadyState + LU_HIST_SVR.C875_4_DPTTransientState + LU_HIST_SVR.C875_4_DPTShutInState,LU_HIST_SVR.C875_4_DPTTransSlope,LU_HIST_SVR.C875_5_DPTSlope,LU_HIST_SVR.C875_5_DPTSteadyState + LU_HIST_SVR.C875_5_DPTTransientState + LU_HIST_SVR.C875_5_DPTShutInState,LU_HIST_SVR.C875_5_DPTTransSlope,LU_HIST_SVR.C918_1_DPTSlope,LU_HIST_SVR.C918_1_DPTSteadyState + LU_HIST_SVR.C918_1_DPTTransientState + LU_HIST_SVR.C918_1_DPTShutInState,LU_HIST_SVR.C918_1_DPTTransSlope,LU_HIST_SVR.C919_3_DPTSlope,LU_HIST_SVR.C919_3_DPTSteadyState + LU_HIST_SVR.C919_3_DPTTransientState + LU_HIST_SVR.C919_3_DPTShutInState,LU_HIST_SVR.C919_3_DPTTransSlope,LU_HIST_SVR.C919_5_DPTSlope,LU_HIST_SVR.C919_5_DPTSteadyState + LU_HIST_SVR.C919_5_DPTTransientState + LU_HIST_SVR.C919_5_DPTShutInState,LU_HIST_SVR.C919_5_DPTTransSlope,LU_HIST_SVR.C919_6_DPTSlope,LU_HIST_SVR.C919_6_DPTSteadyState + LU_HIST_SVR.C919_6_DPTTransientState + LU_HIST_SVR.C919_6_DPTShutInState,LU_HIST_SVR.C919_6_DPTTransSlope,LU_HIST_SVR.C919_7_DPTSlope,LU_HIST_SVR.C919_7_DPTSteadyState + LU_HIST_SVR.C919_7_DPTTransientState + LU_HIST_SVR.C919_7_DPTShutInState,LU_HIST_SVR.C919_7_DPTTransSlope,LU_HIST_SVR.C919_8_DPTSlope,LU_HIST_SVR.C919_8_DPTSteadyState + LU_HIST_SVR.C919_8_DPTTransientState + LU_HIST_SVR.C919_8_DPTShutInState,LU_HIST_SVR.C919_8_DPTTransSlope,LU_HIST_SVR.CMFD875_F1Slope,LU_HIST_SVR.CMFD875_F1SteadyState + LU_HIST_SVR.CMFD875_F1TransientState + LU_HIST_SVR.CMFD875_F1ShutInState,LU_HIST_SVR.CMFD875_F1TransSlope,LU_HIST_SVR.CMFD875_F2Slope,LU_HIST_SVR.CMFD875_F2SteadyState + LU_HIST_SVR.CMFD875_F2TransientState + LU_HIST_SVR.CMFD875_F2ShutInState,LU_HIST_SVR.CMFD875_F2TransSlope,LU_HIST_SVR.CMFD875_F3Slope,LU_HIST_SVR.CMFD875_F3SteadyState + LU_HIST_SVR.CMFD875_F3TransientState + LU_HIST_SVR.CMFD875_F3ShutInState,LU_HIST_SVR.CMFD875_F3TransSlope,LU_HIST_SVR.CMFD875_F4Slope,LU_HIST_SVR.CMFD875_F4SteadyState + LU_HIST_SVR.CMFD875_F4TransientState + LU_HIST_SVR.CMFD875_F4ShutInState,LU_HIST_SVR.CPLEM_PTransSlope,LU_HIST_SVR.CPR01_BPSlope,LU_HIST_SVR.CPR01_BPSteadyState + LU_HIST_SVR.CPR01_BPTransientState + LU_HIST_SVR.CPR01_BPShutInState,LU_HIST_SVR.CPR01_BPTransSlope,LU_HIST_SVR.CPR01_RBasePSlope,LU_HIST_SVR.CPR01_RBasePSteadyState + LU_HIST_SVR.CPR01_RBasePTransientState + LU_HIST_SVR.CPR01_RBasePShutInState,LU_HIST_SVR.CPR01_RBasePTransSlope,LU_HIST_SVR.CPR02_BPSlope,LU_HIST_SVR.CPR02_BPSteadyState + LU_HIST_SVR.CPR02_BPTransientState + LU_HIST_SVR.CPR02_BPShutInState,LU_HIST_SVR.CPR02_BPTransSlope,LU_HIST_SVR.CPR02_RBasePSlope,LU_HIST_SVR.CPR02_RBasePSteadyState + LU_HIST_SVR.CPR02_RBasePTransientState + LU_HIST_SVR.CPR02_RBasePShutInState,LU_HIST_SVR.CPR02_RBasePTransSlope,LU_HIST_SVR.CPR03_BPSlope,LU_HIST_SVR.CPR03_BPSteadyState + LU_HIST_SVR.CPR03_BPTransientState + LU_HIST_SVR.CPR03_BPShutInState,LU_HIST_SVR.CPR03_BPTransSlope,LU_HIST_SVR.CPR03_RBasePSlope,LU_HIST_SVR.CPR03_RBasePSteadyState + LU_HIST_SVR.CPR03_RBasePTransientState + LU_HIST_SVR.CPR03_RBasePShutInState,LU_HIST_SVR.CPR03_RBasePTransSlope,LU_HIST_SVR.CPR04_BPSlope,LU_HIST_SVR.CPR04_BPSteadyState + LU_HIST_SVR.CPR04_BPTransientState + LU_HIST_SVR.CPR04_BPShutInState,LU_HIST_SVR.CPR04_BPTransSlope,LU_HIST_SVR.CPR04_RBasePSlope,LU_HIST_SVR.CPR04_RBasePSteadyState + LU_HIST_SVR.CPR04_RBasePTransientState + LU_HIST_SVR.CPR04_RBasePShutInState,LU_HIST_SVR.CPR04_RBasePTransSlope,LU_HIST_SVR.E874_1_AlignChActiveFirstScan,LU_HIST_SVR.E874_1_ChokeActiveFirstScan,LU_HIST_SVR.E874_1_RestartActiveFirstScan,LU_HIST_SVR.E874_1_ShutInActiveFirstScan,LU_HIST_SVR.E875_1_AlignChActiveFirstScan,LU_HIST_SVR.E875_1_ChokeActiveFirstScan,LU_HIST_SVR.E875_1_RestartActiveFirstScan,LU_HIST_SVR.E875_1_ShutInActiveFirstScan,LU_HIST_SVR.E875_3_AlignChActiveFirstScan,LU_HIST_SVR.E875_3_ChokeActiveFirstScan,LU_HIST_SVR.E875_3_RestartActiveFirstScan,LU_HIST_SVR.E875_3_ShutInActiveFirstScan,LU_HIST_SVR.E875_4_AlignChActiveFirstScan,LU_HIST_SVR.E875_4_ChokeActiveFirstScan,LU_HIST_SVR.E875_4_RestartActiveFirstScan,LU_HIST_SVR.E875_4_ShutInActiveFirstScan,LU_HIST_SVR.E875_5_AlignChActiveFirstScan,LU_HIST_SVR.E875_5_ChokeActiveFirstScan,LU_HIST_SVR.E875_5_RestartActiveFirstScan,LU_HIST_SVR.E875_5_ShutInActiveFirstScan,LU_HIST_SVR.E918_1_AlignChActiveFirstScan,LU_HIST_SVR.E918_1_ChokeActiveFirstScan,LU_HIST_SVR.E918_1_RestartActiveFirstScan,LU_HIST_SVR.E918_1_ShutInActiveFirstScan,LU_HIST_SVR.E919_3_AlignChActiveFirstScan,LU_HIST_SVR.E919_3_ChokeActiveFirstScan,LU_HIST_SVR.E919_3_RestartActiveFirstScan,LU_HIST_SVR.E919_3_ShutInActiveFirstScan,LU_HIST_SVR.E919_5_AlignChActiveFirstScan,LU_HIST_SVR.E919_5_RestartActiveFirstScan,LU_HIST_SVR.E919_5_ShutInActiveFirstScan,LU_HIST_SVR.E919_6_AlignChActiveFirstScan,LU_HIST_SVR.E919_6_ChokeActiveFirstScan,LU_HIST_SVR.E919_6_RestartActiveFirstScan,LU_HIST_SVR.E919_6_ShutInActiveFirstScan,LU_HIST_SVR.E919_7_AlignChActiveFirstScan,LU_HIST_SVR.E919_7_ChokeActiveFirstScan,LU_HIST_SVR.E919_7_RestartActiveFirstScan,LU_HIST_SVR.E919_7_ShutInActiveFirstScan,LU_HIST_SVR.E919_8_AlignChActiveFirstScan,LU_HIST_SVR.E919_8_ChokeActiveFirstScan,LU_HIST_SVR.E919_8_RestartActiveFirstScan,LU_HIST_SVR.E919_8_ShutInActiveFirstScan,LU_HIST_SVR.EPR01_BSDVActiveFirstScan,LU_HIST_SVR.EPR01_GasLiftActiveFirstScan,LU_HIST_SVR.EPR01_GLSDVActiveFirstScan,LU_HIST_SVR.EPR01_OperForceActiveFirstScan,LU_HIST_SVR.EPR01_RBridgedActiveFirstScan,LU_HIST_SVR.EPR01_RestartActiveFirstScan,LU_HIST_SVR.EPR01_ShutInActiveFirstScan,LU_HIST_SVR.EPR01_TSChokeActiveFirstScan,LU_HIST_SVR.EPR02_BSDVActiveFirstScan,LU_HIST_SVR.EPR02_GasLiftActiveFirstScan,LU_HIST_SVR.EPR02_GLSDVActiveFirstScan,LU_HIST_SVR.EPR02_OperForceActiveFirstScan,LU_HIST_SVR.EPR02_RBridgedActiveFirstScan,LU_HIST_SVR.EPR02_RestartActiveFirstScan,LU_HIST_SVR.EPR02_ShutInActiveFirstScan,LU_HIST_SVR.EPR02_TSChokeActiveFirstScan,LU_HIST_SVR.EPR02_TSCompUpsetActiveFirstScan + LU_HIST_SVR.EPR03_TSCompUpsetActiveFirstScan + LU_HIST_SVR.EPR04_TSCompUpsetActiveFirstScan + LU_HIST_SVR.EPR09_TSCompUpsetActiveFirstScan + LU_HIST_SVR.EPR10_TSCompUpsetActiveFirstScan + LU_HIST_SVR.EPR01_TSCompUpsetActiveFirstScan,LU_HIST_SVR.EPR03_BSDVActiveFirstScan,LU_HIST_SVR.EPR03_GasLiftActiveFirstScan,LU_HIST_SVR.EPR03_GLSDVActiveFirstScan,LU_HIST_SVR.EPR03_OperForceActiveFirstScan,LU_HIST_SVR.EPR03_RBridgedActiveFirstScan,LU_HIST_SVR.EPR03_RestartActiveFirstScan,LU_HIST_SVR.EPR03_ShutInActiveFirstScan,LU_HIST_SVR.EPR03_TSChokeActiveFirstScan,LU_HIST_SVR.EPR04_BSDVActiveFirstScan,LU_HIST_SVR.EPR04_GasLiftActiveFirstScan,LU_HIST_SVR.EPR04_GLSDVActiveFirstScan,LU_HIST_SVR.EPR04_OperForceActiveFirstScan,LU_HIST_SVR.EPR04_RBridgedActiveFirstScan,LU_HIST_SVR.EPR04_RestartActiveFirstScan,LU_HIST_SVR.EPR04_ShutInActiveFirstScan,LU_HIST_SVR.EPR04_TSChokeActiveFirstScan,LU_HIST_SVR.FQI_0220_FLOW*1000,LU_HIST_SVR.FQI_0221_FLOW*1000,LU_HIST_SVR.FQI_0225_FLOW*1000,LU_HIST_SVR.FQI_0226_FLOW*1000,LU_HIST_SVR.FQI_6000_FLOW*1000,LU_HIST_SVR.GSLuCPR01_ActiveHHSP,LU_HIST_SVR.GSLUcPR01_Types0OpOverride,LU_HIST_SVR.GSLUcPR01_Types10WRestart,LU_HIST_SVR.GSLUcPR01_Types11TSCompUpset,LU_HIST_SVR.GSLucPR01_Types12RBridged,LU_HIST_SVR.GSLUcPR01_Types1RShutIn,LU_HIST_SVR.GSLUcPR01_Types2WShutIn,LU_HIST_SVR.GSLUcPR01_Types3Choke,LU_HIST_SVR.GSLUcPR01_Types4AlignCh,LU_HIST_SVR.GSLUcPR01_Types5BSDV,LU_HIST_SVR.GSLUcPR01_Types6TSChoke,LU_HIST_SVR.GSLUcPR01_Types7GLSDV,LU_HIST_SVR.GSLUcPR01_Types8GasLift,LU_HIST_SVR.GSLUcPR01_Types9RRestart,LU_HIST_SVR.GSLuCPR02_ActiveHHSP,LU_HIST_SVR.GSLUcPR02_Types0OpOverride,LU_HIST_SVR.GSLUcPR02_Types10WRestart,LU_HIST_SVR.GSLUcPR02_Types11TSCompUpset,LU_HIST_SVR.GSLucPR02_Types12RBridged,LU_HIST_SVR.GSLUcPR02_Types1RShutIn,LU_HIST_SVR.GSLUcPR02_Types2WShutIn,LU_HIST_SVR.GSLUcPR02_Types3Choke,LU_HIST_SVR.GSLUcPR02_Types4AlignCh,LU_HIST_SVR.GSLUcPR02_Types5BSDV,LU_HIST_SVR.GSLUcPR02_Types6TSChoke,LU_HIST_SVR.GSLUcPR02_Types7GLSDV,LU_HIST_SVR.GSLUcPR02_Types8GasLift,LU_HIST_SVR.GSLUcPR02_Types9RRestart,LU_HIST_SVR.GSLuCPR03_ActiveHHSP,LU_HIST_SVR.GSLUcPR03_Types0OpOverride,LU_HIST_SVR.GSLUcPR03_Types10WRestart,LU_HIST_SVR.GSLUcPR03_Types11TSCompUpset,LU_HIST_SVR.GSLucPR03_Types12RBridged,LU_HIST_SVR.GSLUcPR03_Types1RShutIn,LU_HIST_SVR.GSLUcPR03_Types2WShutIn,LU_HIST_SVR.GSLUcPR03_Types3Choke,LU_HIST_SVR.GSLUcPR03_Types4AlignCh,LU_HIST_SVR.GSLUcPR03_Types5BSDV,LU_HIST_SVR.GSLUcPR03_Types6TSChoke",
    "interval": 2.88,
    "frequency": "mi",
    "samplingMethod": "last",
    "quality": "GOOD*",
    "startDate": [
        2020,
        6,
        1,
        22,
        21,
        20
    ],
    "endDate": [
        2020,
        6,
        1,
        23,
        21,
        20
    ]
}'


headers = c('Content-Type'="application/json",'Authorization'= "Bearer some Token")

r_POST <- httr::POST(url,add_headers(headers),body = params,encode = "json",verbose())
http_status(r_POST) #to check errors

r_POST$content

rawJSON <- rawToChar(r_POST$content)
DT <- data.table(fromJSON(rawJSON))  

我在本网站 (https://jsonlint.com/) 上粘贴了 JSON (params) 以检查语法,它显示“valid JSON

如何调试“tagCsv”中的错误?任何指针都会很棒。

你是对的,JSON 有效。
你 运行 遇到的问题是 maximum line length of 4095 bytes that R reads from the console (also discussed )。基本上,长“tagCsv”行在“LU_HIST_SVR.CPR01_RBasePShutInState,LU_HIST_SV”之后被截断,因此,您会遇到所看到的错误。
(RStudio 社区已经指出,这个 is hard-coded in R 因此没有什么是你可以轻易规避的。)

但是,如果您可以选择将此 JSON 写入文件并从那里读取它,那么您应该绝对没问题。

library(jsonlite)

params <- read_json('test.json') # I stored your json in that file

nchar(params$tagCsv)
[1] 10047