表达式或语句中的意外标记
unexpected token in in expression or statement
我想保存一个带有骨架和一些变量的字符串以备后用。
我的字符串:
$moddeduserdata = ("{"Id":$userid,"Timestamp":"$timestamp","FirstName":"$numberout","LastName":"$numberout","CallId":"$numberout"}")
我想要的是下面的输出:
{"Id":261,"Timestamp":"AAAAAAAJ1KM=","FirstName":"5503","LastName":"5503","CallId": "5503"}
所以这会导致错误:
“意外的令牌”
我也尝试过使用 ' ' 而不是 " ",但它只是保存了行而没有输入我的变量。
您正在尝试 在双引号字符串 ("..."
) 中逐字 "
嵌入 个字符,因此您必须 将它们转义为`"
(""
也有效):
$moddeduserdata = "{`"Id`":$userid,`"Timestamp`":`"$timestamp`",`"FirstName`":`"$numberout`",`"LastName`":`"$numberout`",`"CallId`":`"$numberout`"}"
虽然单引号字符串 ('...'
) 允许您嵌入 "
个字符。按原样(无需转义),它们不会执行您需要的字符串插值 (expansion of embedded variable references)。
有关 PowerShell 字符串文字的详细信息,请参阅 this answer 的底部部分。
或者制作一个对象然后将其转换为压缩文件json:
$userid,$timestamp,$numberout,$numberout,$numberout = echo 261 AAAAAAAJ1KM 5503 5503 5503
[pscustomobject]@{Id=$userid;Timestamp=$timestamp;FirstName=$numberout;
LastName=$numberout;CallId=$numberout} | convertto-json -compress
{"Id":261,"Timestamp":"AAAAAAAJ1KM=","FirstName":"5503","LastName":"5503","CallId":"5503"}
我想保存一个带有骨架和一些变量的字符串以备后用。
我的字符串:
$moddeduserdata = ("{"Id":$userid,"Timestamp":"$timestamp","FirstName":"$numberout","LastName":"$numberout","CallId":"$numberout"}")
我想要的是下面的输出:
{"Id":261,"Timestamp":"AAAAAAAJ1KM=","FirstName":"5503","LastName":"5503","CallId": "5503"}
所以这会导致错误: “意外的令牌”
我也尝试过使用 ' ' 而不是 " ",但它只是保存了行而没有输入我的变量。
您正在尝试 在双引号字符串 ("..."
) 中逐字 "
嵌入 个字符,因此您必须 将它们转义为`"
(""
也有效):
$moddeduserdata = "{`"Id`":$userid,`"Timestamp`":`"$timestamp`",`"FirstName`":`"$numberout`",`"LastName`":`"$numberout`",`"CallId`":`"$numberout`"}"
虽然单引号字符串 ('...'
) 允许您嵌入 "
个字符。按原样(无需转义),它们不会执行您需要的字符串插值 (expansion of embedded variable references)。
有关 PowerShell 字符串文字的详细信息,请参阅 this answer 的底部部分。
或者制作一个对象然后将其转换为压缩文件json:
$userid,$timestamp,$numberout,$numberout,$numberout = echo 261 AAAAAAAJ1KM 5503 5503 5503
[pscustomobject]@{Id=$userid;Timestamp=$timestamp;FirstName=$numberout;
LastName=$numberout;CallId=$numberout} | convertto-json -compress
{"Id":261,"Timestamp":"AAAAAAAJ1KM=","FirstName":"5503","LastName":"5503","CallId":"5503"}