Suave Nti
Suave Nti

Reputation: 3747

Invalid JSON primitive: object : Passing Object as a Parameter from aspx

Am receiving a JSON object from webservice in C# using the below script

    $.ajax({
            type: "POST",
            url: "Services/LogService.asmx/authenticateLogin",
            data: "{'gopId':'" + txtGopId+ "'}",
            contentType: "application/json; charset=utf-8",
            success: function (response) 
            {
                var k = $("#hidId").val(response.d);                   
                window.location.replace("Pages/Reved.aspx?hid="+k+"");                           
            },
            error: function (xhr, status, error) {

                DisplayError(xhr);
            }
        }); 

hidId is a hidden feild.

On sucess am forwarding the Object to another aspx page and trying to deserialize this on page_load

         JavaScriptSerializer serializer = new JavaScriptSerializer();
         userBO = serializer.Deserialize<UserBO>(Request["hid"]);

Am I doing some thing wrong? as iam facing this error: Invalid JSON primitive: object

Upvotes: 2

Views: 6512

Answers (1)

Harper Shelby
Harper Shelby

Reputation: 16583

The "Invalid JSON primitive" error message means that whatever you're sending to the deserializer is not JSON. Have you verified that the value you're putting into the hidId field is valid JSON?

Upvotes: 4

Related Questions