willsonchan
willsonchan

Reputation: 200

Javascript json error Invalid JSON primitive: strJson

I've written a jQuery demo to post JSON:

$.ajax({
    url: "RoleFunc.aspx/Vonvert",
    type: "POST",
    contentType: "application/json; charset=utf-8",
    dataType: 'json',
    data: { "strJson": json },                   

    success: function(result) {
        alert(result);    
    },
    error: function() {
        alert("error");
    }
});

and when I use the function, Firebug view shows as an error message like Invalid JSON primitive: strJson.

I've tested the JSON and the result is

{ "strJsonssss":[{"Role_ID":"2","Customer_ID":"155","Brands":"Chloe;","Country_ID":"96;"}]}

and my C# func is

[WebMethod]
public static int Vonvert(string strJson)
{
    //DataSet dt1 = JsonConvert.DeserializeObject<DataSet>(strJsonssss);   

    return 1;
}

I debug it, and it never in to the function so... any body help me...

Upvotes: 1

Views: 628

Answers (2)

Krish R
Krish R

Reputation: 22711

Also, you can validate and verify your json objects using this online tool .http://jsonformatter.curiousconcept.com/#jsonformatter

Upvotes: 0

Taylan Aydinli
Taylan Aydinli

Reputation: 4363

You are missing a closing quote:

{ "strJsonssss":[{"Role_ID":"2","Customer_ID":"155","Brands":"Chloe;","Country_ID":"96;"}]}
--------------^

Upvotes: 4

Related Questions