你好我使用JSON的firsttime在asp.net在asp.net中序列化爲JSON?
我有我的WebMethod這樣
[WebMethod]
[ScriptMethod(ResponseFormat = ResponseFormat.Json)]
public static string Vo_Get(string Action,int ID)
{
Product p= new Product();
DataSet ds= new DataSet();
p.Action = Action;
p.ID= ID;
ds= VoGet_Get(obj);
**string jsonVesselDetails = JsonConvert.SerializeObject(ds, Formatting.None);
return jsonVesselDetails;**
}
這裏IAM讓我的結果作爲
[
{
"Pinky": 1,
"Ponky": "Breakwater Dockk",
},
{
"Pinky": 2,
"Ponky": "Watson Island Dock",
},
但是當我試圖用調用Ajax並附加到表中它給予Unexpexted Token U如果我嘗試綁定結果並給出意想不到的標記O如果我嘗試綁定result.data
終於讓我找到問題是系列化,
我的Ajax調用是
$.ajax({
type: "POST",
contentType: "application/json; charset=utf-8",
url: "Voyage.aspx/Vo_Get",
data: "{'Action':'Get','ID':'68'}",
dataType: "json",
success: function (data) {
try {
alert("getdata! success");
Get(data);
} catch (ex) {
alert(ex);
}
},
error: function (msg) {
alert("err: " + error);
}
});
和
指定DateFormathandling看到螢火蟲的響應,它可能會導致類似d的東西。因爲安全原因,Coz,asp.net圍繞json結果「d」,這是一種jsonp(帶有Padding的JSON)類型 – 2013-03-27 09:34:15