问题描述
我对 AutoHotkey 还很陌生,我用它来将 API JSON 文件从 URL 拉入文件。我已经想出了如何替换单行文本来替换无效的 JSON 对象,但现在我正在尝试在文件中找到一个模式,并在将文件解析为 sql 表之前添加另外两行。
目前正在寻找以下多行模式:
<CytoscapeComponent
layout={{ name: "circle" }}
elements={elements}
style={ { width: '600px',height: '600px' } }
stylesheet={[
{
selector: 'edge',style: {
width: 5,targetArrowShape: 'triangle',curveStyle: 'bezier'
}
}
]}
/>
需要在第一行后添加以下两行:
"AAA": x.xx,*Note: x.xx is a decimal number that can change per record.*
}
最终结果需要:
"BBB" {
"CCC": NULL
解决方法
编辑 JSON 文件时,有很多更好的方法可以做到这一点。但是,如果您只想插入一些行,您可以这样做:
oldFile := "original_file.json"
newFile := "edited_file.json"
insertText =
(
"BBB" {
"CCC": NULL
)
Loop,Read,% oldFile,% newFile
{
FileAppend,%A_LoopReadLine%`n
; If last written line is a match,add new lines
if RegExMatch(A_LoopReadLine,"""AAA"": \d+.\d+,")
{
FileAppend,%insertText%`n
}
}