我正在尝试读出从后面的代码中的函数给出的JSON数据。我有这个设置:
代码背后:
<WebMethod()>
Public Shared Function LoadVolgNummer(ByVal EnqDGId As String, ByVal VolgordeId As String) As String
Dim oRetValue As EnqueteVraag = Nothing
Try
oRetValue = EnqueteDetail.LoadQuestion(EnqDGId, VolgordeId)
Catch ex As Exception
ReportError(ex.Message, GetCurrentMethod.Name)
End Try
Dim serializer As New JavaScriptSerializer
Dim JSON As String = serializer.Serialize(oRetValue).ToArray
Return JSON
End Function
这是我从函数中返回的JSON字符串:
{"questionid":1,"question":"De dienstverlening van xxx in het algemeen"}
页面上的JQUERY:
$.ajax({
type: "POST",
url: "enquete.aspx/LoadVolgNummer",
data: JSON.stringify({EnqDGId: '1', VolgordeId: '1'}),
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (msg) {
alert(msg.question);
},
error:function() {
alert('failure in loading volgnummer')
}
});
Enquetevraag类:
Public Class EnqueteVraag
Public questionid As Integer
Public question As String
结束班
结果是成功但我无法读出jQuery中的数据。它显示我'未定义'。任何帮助表示赞赏。
亲切的问候
答案 0 :(得分:1)
感谢Felix King和Jan Dvorak结案!
JSON.parse(msg.d)。提问
答案 1 :(得分:0)
试试这个:
function getQuestions()
{
var jsonData = $.ajax({
url: "enquete.aspx/LoadVolgNummer",
data: JSON.stringify({EnqDGId: '1', VolgordeId: '1'}),
dataType: "json",
async: false
}).responseText;
jsonData = JSON.parse(jsonData);
alert(jsonData.question);
}