I have some json which is being returned from an asp.net function. I'm only testing this out so far but what I have at the moment is:
Public Structure myarray
Dim name As String
End Structure
<WebMethod()> _
Public Shared Function temp(ByVal strTerm As String) As String
Dim user(1) As myarray
user(0).name = "John"
user(1).name = "Joe"
Dim serializer As New JavaScriptSerializer()
Dim arrayJson As String = serializer.Serialize(user)
Return arrayJson
End Function
and for the jquery I have:
jQuery.ajax({
type: "POST",
url: "default.aspx/temp",
data: "{'strTerm':'" + req.term + "'}",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (data) {
var suggestions = [];
$.each(data, function (i, val) {
//alert(val);
suggestions.push(val);
});
add(suggestions);
},
error: function (XMLHttpRequest, textStatus, errorThrown) {
alert('unable to create ticket');
}
});
What I'm looking for in the
$.each(data, function (i, val) {
//alert(val);
suggestions.push(val);
});
is to get each of the names I've specified, i.e. John & Joe and add them to the "suggestions" array .Not sure if the Json is in the correct format for this.
The json being returned is:
[{"name":"John"},{"name":"Joe"}]
Any ideas how's the correct way to do this?
Thanks,