我正在尝试格式化json有效负载,但是我在Params属性中遇到语法错误
mailer.send2(new PayoutEmailModel
{
medium = "email",
name = "sap_finance_supplier_payout",
@params = @"{""supplier"":""" + BeneficiaryName + """,""lastfourdigits"":""" + AccountNo + """,""amount"":""" + Amount + """,""valuedate"":""" + BeneficiaryName + """,""time"":""" + BeneficiaryName + """}",
recipient = "dapo.olotu@konga.com",
sender = "no-reply@konga.com",
subject = "Payment Notification",
sender_id = "Konga"
});
编辑, 我需要@Params正确呈现如下
{"supplier":"foo","lastfourdigits":"foo","amount":"foo","valuedate":"foo","time":"foo"}
答案 0 :(得分:1)
尝试使用匿名类型
mailer.send2(new PayoutEmailModel
{
medium = "email",
name = "sap_finance_supplier_payout",
params = new { supplier = BeneficiaryName, lastfourdigits = AccountNo, amount = Amount, valuedate = BeneficiaryName, time = BeneficiaryName},
recipient = "dapo.olotu@konga.com",
sender = "no-reply@konga.com",
subject = "Payment Notification",
sender_id = "Konga"
});
答案 1 :(得分:1)
我认为Dinesh是对的,你可能不会按照自己的方式获得预期的结果。但是,要回答您的问题,语法错误是因为您为每个+
运算符启动了一个新字符串,但您没有使用新的@
作为前缀:
@“{”“supplier”“:”“”+ + BeneficiaryName + @“”“,”“lastfourdigits”“:”“”+ AccountNo + @“”“,”“amount”“:”“”+金额+ @“”“,”“有价值”“:”“”“+受益人姓名+ @”“”,“”时间“”:“”“+受益人姓名+ @”“”}“,