Edwin O.
Edwin O.

Reputation: 5276

Properly format json payload

I am trying to format json payload as such, but i am getting a syntax error at the Params property

   mailer.send2(new PayoutEmailModel
                    {
                        medium = "email",
                        name = "sap_finance_supplier_payout",
                        @params = @"{""supplier"":""" + BeneficiaryName + """,""lastfourdigits"":""" + AccountNo + """,""amount"":""" + Amount + """,""valuedate"":""" + BeneficiaryName + """,""time"":""" + BeneficiaryName + """}",
                        recipient = "[email protected]",
                        sender = "[email protected]",
                        subject = "Payment Notification",
                        sender_id = "Konga"
                    });

Edit, I need @Params proper to render as below

{"supplier":"foo","lastfourdigits":"foo","amount":"foo","valuedate":"foo","time":"foo"}

Upvotes: 0

Views: 101

Answers (2)

Crowcoder
Crowcoder

Reputation: 11514

I think Dinesh is right, you probably won't get the results you expect by doing it your way. But, to answer your question, the syntax error is because you start a new string with every + operator but you do not prepend with a new @:

@"{""supplier"":""" + BeneficiaryName + @""",""lastfourdigits"":""" + AccountNo + @""",""amount"":""" + Amount + @""",""valuedate"":""" + BeneficiaryName + @""",""time"":""" + BeneficiaryName + @"""}",

Upvotes: 1

Dinesh
Dinesh

Reputation: 480

Try using anonymous type

mailer.send2(new PayoutEmailModel
    {
        medium = "email",
        name = "sap_finance_supplier_payout",
        params = new { supplier = BeneficiaryName, lastfourdigits = AccountNo, amount = Amount, valuedate = BeneficiaryName, time = BeneficiaryName},
        recipient = "[email protected]",
        sender = "[email protected]",
        subject = "Payment Notification",
        sender_id = "Konga"
    });

Upvotes: 1

Related Questions