json - 如何替换 JSON 键值?
问题描述
{"enable"=false,
"datatype"="DB",
"report"=false}
我需要将enable
值更改为true
. 现在我正在使用以下代码:
(Get-Content 'C:\Shibi\Basic.json') -replace 'false', 'true' | Set-Content 'C:\Shibi\Basic.json'
解决方案
如果您要使用文本文件而不是真正的 JSON 结构,则可以使用*-Content
带有操作符的命令-replace
。
(Get-Content 'C:\Shibi\Basic.json') -replace '"enable"=false','"enable"=true' | Set-Content
注意: Set-Content将使用替换的数据更新 Basic.json 文件。
您可以将-Raw
开关添加到Get-Content以保留原始文件的空格或换行符。
推荐阅读
- google-cloud-platform - Microsoft Authenticode 代码签名 (EV) + Google Cloud HSM?
- python - IndexError ::: 列表索引超出范围
- android - 如何测试 gradle 插件构建速度的影响
- msbuild - 从 Build Pipeline 的 bin 文件夹中删除一个 DLL
- android - Android Studio 3.5 在我的智能手机上部署问题
- postgresql - 引起:org.springframework.beans.factory.BeanCreationException:使用Spring Boot 2创建名称错误的bean时出错
- angular-material - mat-form-field floatLabel="never" 不起作用
- haskell - 如何创建一个接受参数列表并返回将参数应用于另一个函数的函数的函数
- php - 使用函数作为 while 参数,如 Wordpress
- reactjs - 在 React 和 Typescript 中只允许特定组件作为子组件