Adam92 Adam92 - 5 months ago 11
JSON Question

Deserialising JSON Data

I've an example string being return through a post call to an ASP handler.

alert("Data: " + data);


Is working and alerting the string.

[{"Item1":"stringone","Item2":"stringtwo"}]


I cant seem to be able to access the data in Item1 and Item2 so I can enter it into a textbox?

$('#txtFOA').val(data[0]);
$('#txtAddress').val(data[2]);

Answer

You should first parse that string to JSON like this:

var jsonified = JSON.parse(data);

then you can access its elements like this:

jsonified[0].Item1
Comments