json - hudson.remoting.ProxyException:net.sf.json.JSONException:无效的 JSON 字符串
问题描述
尝试在 Jenkins 中解析 json 文件时遇到以下错误
def appconfig="./appSettings.json"
def testconfig= readJSON file: appconfig;
json文件
{
"Configuration": {
"ConnectionString": "",
"ConnectionString2": "",
"UnProcessedHeaderFilePath": "\\\\edisilon01\\prod\\Reporting\\GET\\Header-{0:yyyyMMddHHmmss}.txt",
"UnProcessedDetailFilePath": "\\\\edisilon01\\prod\\Reporting\\GET\\Detail-{0:yyyyMMddHHmmss}.txt",
"ApplicationTriggerFile": "\\\\edisilon01\\PROD\\Reporting\\InputFiles\\Factor\\DR\\Factor.txt",
"DB2ConnectionString": ""
},
"Serilog": {
"Using": [ "Serilog.Sinks.Console" ],
"MinimumLevel": "Information",
"WriteTo": [
{ "Name": "Console" },
{
"Name": "File",
"Args": {
"path": "\\\\ECPCICS\\Files\\Generator\\log\\log-.txt",
"rollingInterval": "Day",
"outputTemplate": "{Timestamp:dd-MMM-yyyy HH:mm:ss.fff zzz} [{Level:u3}] {Message:lj}{NewLine}{Exception}"
}
}
]
}
}
错误
hudson.remoting.ProxyException: net.sf.json.JSONException: 在 net.sf.json.JSONSerializer.toJSON(JSONSerializer.java:143) 在 net.sf.json.JSONSerializer.toJSON(JSONSerializer.java:103) 的 JSON 字符串无效) 在 net.sf.json.JSONSerializer.toJSON(JSONSerializer.java:84) 在 org.jenkinsci.plugins.pipeline.utility.steps.json.ReadJSONStepExecution.doRun(ReadJSONStepExecution.java:77) 在 org.jenkinsci.plugins。 pipeline.utility.steps.AbstractFileOrTextStepExecution.run(AbstractFileOrTextStepExecution.java:32) at org.jenkinsci.plugins.workflow.steps.SynchronousNonBlockingStepExecution.lambda$start$0(SynchronousNonBlockingStepExecution.java:47) at java.util.concurrent.Executors$RunnableAdapter .call(Executors.java:511) 在 java.util.concurrent.FutureTask.run(FutureTask.java:266) 在 java.util.concurrent。ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) 在 java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) 在 java.lang.Thread.run(Thread.java:748)
解决方案
除了有关前导/尾随空格的其他答案之外,这也可能是由文件开头的字节顺序标记引起的。
我将文件的编码从带有 BOM 的 UTF-8 更改为 UTF-8,它解决了问题。
推荐阅读
- angularjs - 将控制器中的对象行为定义绑定到 angularjs 中的指令范围函数
- python - 带有 Umap 的卷积神经网络
- java - 反射是否适用于类加载器?
- javascript - 根据子组件中的变量状态在 NuxtJS 中设置标题
- machine-learning - 为什么easyocr在本地开发机器上占用更多内存而在google colab上占用更少?
- reactjs - 类型错误:无法将 undefined 或 null 转换为对象
- ssh - 如何使 tmux 窗格确定运行比 SSH 会话更深的命令
- html - css - 内容区域侧跨度的意外位置
- pyspark - 有没有办法从 pyspark MFlow 库向 BinaryClassificationEvaluator 添加自定义(几乎所有流行的)指标?
- android-studio - 如何使用带有 SerializedName 的变量