I am working on the GUI for a web app and they want me to use json to get values. I have a simple script to pull the value of a key, but it’s not working.
HTML
<div class="get-data">
<p>Get Data</p>
<div class="json">
<!--<p> will be created here -->
</div>
</div>
JSON
[
{
"id":-596859137166526783,
"avatarDefinitionId":2,
"tenantId":1,
"avatarName":"qln320",
"attributes":{
"qln320.set.media.handling":"TEAR_OFF",
"qln320.snr.memory.free":"66939392",
}
}
]
jQuery
$.getJSON('json/test.json', function(data) {
var items = [];
data[0].attributes['qln320.snr.memory.free'];
$('<p/>', {
'class': 'raw-list',
html: items.join('')
}).appendTo('.json');
});
You are iterating through
attributesobject,valin your code returns value ofqln320.set.media.handlingandqln320.snr.memory.freeproperties, in fact it returns"TEAR_OFF"and"66939392", but you are pushing hard-codedval.qln320.snr.memory.freestrings regardless of the returned values.http://jsfiddle.net/XDZ8Y/
However the error,
[TypeError: a is undefined]is not be related to the posted script.