[英]Merge JSON Files (Newtonsoft.Json.JsonReaderException)
I am trying to merge FILE 2 into FILE 1. I cant seem to come right with my code and I suspect I am not declaring the JSON files properly. 我正在尝试将FILE 2合并到FILE 1中。我的代码似乎无法正确显示,我怀疑我没有正确声明JSON文件。 I keep getting an error - see below
我不断收到错误-见下文
MY CODE: 我的密码:
string DestinationFile = @"C:\Lang Compare\Original\language.json";
string ImportFile = @"C:\Lang Compare\New\language.json";
JObject FileObject1 = JObject.Parse(DestinationFile);
JObject FileObject2 = JObject.Parse(ImportFile);
FileObject1.Merge(FileObject2, new JsonMergeSettings
{
MergeArrayHandling = MergeArrayHandling.Union
});
string FinalJson = FileObject1.ToString();
MessageBox.Show(FinalJson);
JSON FILE 1 JSON档案1
{
"AverageChipStackTitle": "筹码中位数 ",
"MedianChipStackTitle": "中位数堆",
}
JSON FILE 2 JSON档案2
{
"AverageChipStackTitle": "堆平均值 %NEW%",
"MedianChipStackTitle": "堆中位数 %NEW%",
"TargetChipStackTitle": "目标筹码堆",
}
You're not reading the files, you're parsing the filenames as JSON. 您没有读取文件,而是将文件名解析为JSON。 The exception clearly mentions the unexpected character
C
at position 0, being the start of C:\\Lang...
. 异常清楚地提到了位置0处的意外字符
C
,它是C:\\Lang...
。
Read the files instead: 改为读取文件:
JObject FileObject1 = JObject.Parse(File.ReadAllText(DestinationFile));
JObject FileObject2 = JObject.Parse(File.ReadAllText(ImportFile));
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.