json - 如何在 JSON 输出中避免 \n
问题描述
尝试在PowerShell中将对象转换为字符串,输出\n
在每行之后给出,如果我删除$result = $result | Out-String
它会抛出
无法将“System.Object[]”转换为参数“Value”所需的类型“System.String”。不支持指定的方法。
$result = @( )
$result = $result | Out-String
foreach ($point in $j) {
$seconds = [long]$point.Time
$point.Time = Get-EpochDate $seconds
$result += "`n" + $point.Time
}
输出是
[
{
"key": "Time",
"value": "\"\\n07/30/2019 17:34:16\\n07/29/2019 15:23:20\\n07/29/2019 13:54:05\""
}
]
期待
[
{
"key": "Time",
"value": "07/30/2019 17:34:1,
07/29/2019 15:23:20,
07/29/2019 13:54:05"
}
]
解决方案
推荐阅读
- python - 未解决的导入模型 Django + Docker
- jquery - JQuery select2(4.0.9)在动态表中引发事件或获取为:('focus')
- javascript - Javascript最有效的方法来组合数组元素
- c# - 当对象经过特定旋转时播放声音
- javascript - 从 json 层次结构中的较低键嵌套或映射数据
- python - 用while循环取平均值
- react-native-gifted-chat - 反应原生天才聊天中的快速回复未显示
- go - 当没有这样的文件返回错误为 nil 时如何使用 os.Open
- sql - PostgreSQL 11 在行中选择前一个值以与 out sub select 进行比较
- javascript - 我如何让我的代码让用户提交一个品种的狗并返回特定品种的图片