Skip to main content
 首页 » 编程设计

c#之Javascript json 错误 Invalid JSON primitive : strJson

2024年02月13日37txw1958

我写了一个 jQuery 演示来发布 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"); 
    } 
}); 

当我使用该函数时,Firebug View 显示为错误消息,如 Invalid JSON primitive: strJson.

我测试了JSON,结果是

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

我的 C# 函数是

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

我调试了它,但它从未进入函数,所以...任何人都可以帮助我...

请您参考如下方法:

您缺少结束语:

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