I have some server side methods returning a JSON object that my JS parses and tries to enumerate through the properties to set the input with the same name as the property value. My application is in ASP.Net MVC 5 and I got the JSON working correctly.
Here is my JS:
function ProcessPropertyChange(url, name)
{
var val = $("[name='" + name + "'").val();
url = url + "&propValue=" + val;
$.get(url, function (data) {
var obj = JSON.parse(data);
for (var prop in obj)
{
if(obj.hasOwnProperty(prop))
{
$("[name='" + prop + "'").text = obj[prop];
alert(prop);
}
}
});
}
An example JSON string would be:
[{"FullAddress" : "123 w. oak", "ParentName":""}]
That was taken from my code.
When I view my object in the developer's console I can see the properties with the proper names, FullAddress and ParentName, however when I try to enumerate through them it returns "0" and the value of obj[prop] is always [Object object].
Any ideas? Can post more code if you need.
Thanks!
$("[name='" + prop + "']").text = obj[prop];var obj = JSON.parse(data);.