为了在Google Chrome浏览器中安装外部扩展程序,我尝试更新chrome外部扩展json文件.使用Json.NET它似乎很容易:
string fileName = "..."; // path to chrome external extension json file
string externalExtensionsJson = File.ReadAllText(fileName);
JObject externalExtensions = JObject.Parse(externalExtensionsJson);
但我得到一个Newtonsoft.Json.JsonReaderException说法:
"Error parsing comment. Expected: *, got /. Path '', line 1, position 1." 
在调用时,JObject.Parse因为此文件包含:
// This json file will contain a list of extensions that will be included
// in the installer.
{
}
和注释不是json的一部分(如何在Json.NET输出中添加注释?).
我知道我可以用正则表达式删除注释(正则表达式删除javascript双斜杠(//)样式注释)但我需要在修改后将json重写到文件中并保持评论可能是一个很好的想法.
问题:有没有办法在没有删除它们的情况下读取带有注释的json并能够重写它们?