简体   繁体   English

合并JSON文件(Newtonsoft.Json.JsonReaderException)

[英]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.

相关问题 Newtonsoft.Json.JsonReaderException MobileServicesClient RegisterAsync - Newtonsoft.Json.JsonReaderException MobileServicesClient RegisterAsync Newtonsoft.Json.JsonReaderException,无法找到程序集“ Newtonsoft.Json…” - Newtonsoft.Json.JsonReaderException, Unable to find assembly 'Newtonsoft.Json…' C# Discord Bot 错误:Newtonsoft.Json.JsonReaderException - C# Discord Bot Error: Newtonsoft.Json.JsonReaderException Newtonsoft.Json.JsonReaderException:无法将字符串转换为日期时间: - Newtonsoft.Json.JsonReaderException: Could not convert string to DateTime: Newtonsoft.Json.JsonReaderException 无法识别左方括号“[” - Newtonsoft.Json.JsonReaderException does not recognize left square bracket “[” Newtonsoft.Json.JsonReaderException:'解析值时遇到意外字符:[。 - Newtonsoft.Json.JsonReaderException: 'Unexpected character encountered while parsing value: [. Newtonsoft.Json.JsonReaderException 输入字符串“0.64”不是有效的 integer - Newtonsoft.Json.JsonReaderException Input string '0.64' is not a valid integer Newtonsoft.Json.JsonReaderException:无效的 JavaScript 属性标识符字符:, - Newtonsoft.Json.JsonReaderException: Invalid JavaScript property identifier character: , Newtonsoft.Json.JsonReaderException:未终止的字符串。 预期的分隔符 - Newtonsoft.Json.JsonReaderException: Unterminated string. Expected delimiter Newtonsoft.Json.JsonReaderException:'解析值时遇到意外字符: - Newtonsoft.Json.JsonReaderException: 'Unexpected character encountered while parsing value:
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM