This is for use in a simple webserver made with a microcontroller. Consider that the microcontroller application have a total of 256 properties, each one with its own value. When the browser makes a request to read the properties from the microcontroller, a random number of properties will be returned in JSON format, ranging from fields perperty1 to property256. For example, properties 1, 15, 20, 60, 123, 200, 230, 256, that is, in almost all answers of the microcontroller it doesn't contain 256 properties, its a random number of properties.
I want to display the values of the properties which were received from the microcontroller in a text box in html, but the test code below is not working, I am getting unexpected output "property1 = undefined, property256 = undefined, ". I want it outputs "property1 = 1234, property256 = 5678, "
<head>
<title>JAVASCRIPT_TEST</title>
<meta charset="UTF-8"/>
</head>
<body>
<input type="text" id="result_text" size="150">
<input type="button" onclick="test()" value="TEST">
<script>
function test()
{
document.getElementById("result_text").value = "";
var obj = JSON.parse('{"property1":"1234","property256":"5678"}');
for (var i=1; i<=256; i++)
{
var property = "property"+i;
if (property in obj)
{
document.getElementById("result_text").value += ( property+" = "+obj.property+", " );
}
}
}
</script>
</body>