为了将外部扩展安装到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);@H_404_3@但是我得到一个Newtonsoft.Json.JsonReaderException说:
"Error parsing comment. Expected: *,got /. Path '',line 1,position 1."@H_404_3@当调用JObject.Parse时,因为此文件包含:
// This json file will contain a list of extensions that will be included // in the installer. { }@H_404_3@并且评论不是json的一部分(如How do I add comments to Json.NET output?所示)。 @H_404_3@我知道我可以使用正则表达式(Regex to remove javascript double slash (//) style comments)删除评论,但是我需要在修改后将json重写为文件,并保持评论可以很好的想法。 @H_404_3@问题:有没有办法读取json的评论而不删除它们,并能够重写?