Error while parsing a Json object
From my jQuery file, I call a function from my controller which returns a Json object, as below:
[AcceptVerbs(HttpVerbs.Get)]
public ActionResult MatrixTypes()
{
var matrix = Enum.PricingMatrixType();
return Json(matrix);
}
The call is made by the following function, I'm posting only an excerpt that really matters:
var matrix;
$.get(
MatrixTypeUrl,
function(data) {
matrix = JSON.parse(data);
for (var i = 0; i < matrix.length; i++) {
html += String.format('<option value="{0}">{1}</option>', matrix[i].Value, matrix[i].Text);
}
When I press a button on my page, this function gets correctly called, but blows up at the line "matrix = JSON.parse(data);"
The data object has data, I double checked it on the call by debugging.
This was the error I got:
JSON.parse [Break on this error] matrix = JSON.parse(data);
What do you thi开发者_运维知识库nk I can do about this?
EDIT: By using Firebug, I could also confirm that the JSON object is not empty, this is the response of the server:
[{"Text":"Valor Único","Value":"0"},{"Text":"Intervalo","Value":"1"},{"Text":"Valor Adicional","Value":"2"}]
Nevermind this problem, I fixed it. It was missing some calls at the initializer of the jQuery class and so it had errors way before it arrived at the call of JSON.parse(data).
精彩评论