tac o2
tac o2

Reputation: 21

C# Google API - Invalid JSON payload received

I'm about to create a request to googles API, the purpose is the change the signature of a gmail account.

This is the part of the request that is triggering an error. If I change the 'signature' string to this 'Test', everything is woring fine. I know it must has something to do with the formatting I just can't seem to find the issue.

            string signature = "<div>Med venlig hilsen / regards,</div><div><br></div><div><strong>" + "Name" + "</strong></div>" +
                            "<div><em>" + "Role" + "</em></div>" +
                            "<div><a href=\"www.xxx.com/da/\"style=\"color:rgb(17,85,204);\"target=\"_blank\"><strong>xxxx xxxxx</strong></a></div>" +
                            "<div>Tel. " + "Phone" + "</div>" +
                            "<div>E-mail: <a href=\"mailto:" + "Mail" + "\"style=\"color:rgb(17,85,204);\"target=\"_blank\">" + "Mail" + "</a></div>" +
                            "<div><a href =\"www.xxx.com/da/\"style=\"color:rgb(17,85,204);\"target=\"_blank\"><img src=\"www.xxx.com/wp-content/uploads/2018/09/xxxxx-logo-7.png\"></a></div>" +
                            "<br></br><div>xxx<br> Reg.no. xxx- <a href =\"www.xxx.com/\"style=\"color:rgb(17,85,204);\"target=\"_blank\">www.xxx.com</a></div>";

The error is as follows:

    {
      "error": {
        "code": 400,
        "message": "Invalid JSON payload received. Expected , or } after key:value pair.\n\u003cdiv\u003eMed venlig hils\n^",
        "errors": [
          {
            "message": "Invalid JSON payload received. Expected , or } after key:value pair.\n\u003cdiv\u003eMed venlig hils\n^",
            "domain": "global",
            "reason": "parseError"
          }
        ],
        "status": "INVALID_ARGUMENT"
      }
    }

Thanks in advance!

Upvotes: 2

Views: 2856

Answers (2)

Sh.Imran
Sh.Imran

Reputation: 1033

Back slashes \ are the issue in your Json. With \ Json not works properly. If you can remove this then it will work.

Upvotes: 1

tac o2
tac o2

Reputation: 21

Thanks to Sh.Imran for coming up with the solution

Back slashes ` are the issue in your Json. With ` Json not works properly. If you can remove this then it will work.

Upvotes: 0

Related Questions