json - 调用 PowerShell 脚本时出现 Azure 扩展错误
问题描述
使用 PowerShell,我正在尝试将文本文件编码为字符串,并提供编码字符串作为输入以获取食谱名称和食谱详细信息。当我检查输出说明书名称和 Json 文件时,它们是字符串和有效的 json 文件。但是当我通过 Azure 扩展使用此代码时,我收到错误消息:
ConvertFrom-Json :传入的未终止字符串。 FullyQualifiedErrorId : System.ArgumentException,Microsoft.PowerShell.Commands.ConvertFromJsonCommand
#Encode the Input file
[string]$sStringToEncode=Get-Content "c:\temp\json.txt"
$sEncodedString=[Convert]::ToBase64String([System.Text.Encoding]::UTF8.GetBytes($sStringToEncode))
write-host -ForegroundColor Green "Encoded String:`n" $sEncodedString
#Decode text
$EncodedText = $sEncodedString.replace("\n","")
write-host "String after replacing \n:" $EncodedText
$DecodedText = [System.Text.Encoding]::ASCII.GetString([System.Convert]::FromBase64String($EncodedText))
#Convert to Json file
$DecodedText | ConvertFrom-Json | ConvertTo-Json | Out-File c:\temp\DNAFiledata.json
#Taking out cookbook Name
$CookbookName = (Get-Content c:\temp\DNAFiledata.json | Out-String | ConvertFrom-Json).cookbook_name
$CookbookName | Out-File "c:\temp\3_CookBookName.txt"
#Taking out recipe details
$Datainput = (Get-Content -Raw -Path c:\temp\DNAFiledata.json | ConvertFrom-Json).chef_attributes | ConvertTo-Json
$Datainput | Out-File "c:\temp\4_Datainput.json"
$Datainput | Set-Content "c:\temp\$CookbookName.json"
请对此提出任何建议。
解决方案
推荐阅读
- c++ - 集合中的比较器如何与 C++ 中的仿函数一起使用?
- c++ - 检查板中的项目旁边是否有任何东西(二维数组)
- python - 在python中将字符串放在类似字节的对象上
- javascript - JavaScript / HTML 使用 getElementById
- wordpress - Wordpress:如何使用 wp i18n 翻译自定义 Composer 包?
- python - 如果测试套件作为进程执行,则骑行会卡住
- python - 如何在新的谷歌广告 python 库中更新广告系列预算?
- javascript - FB Share JavaScript“未定义share_button”
- python - 获取单元格的行和列,xlwings UDF在哪里被调用?
- c++ - 中间的 C++ 可变参数模板更改元素