DCJones DCJones - 9 months ago 52
jQuery Question

json curly brackets displaying in Div that display the json result

I have a Jquery script that does a lookup on a data table and returns a result.

However, when I display the result inside a DIV the curly brackets surrounding the json data are also displayed. Can anyone see where I have gone wrong.

My script:

$.get('check_override_image.php', { RecordID: form2.board.value },
function(result) {

The Json result is:


I am displaying the result using

<div id="size"></div>

What I want to display is DisplayWidth:1080,DisplayHeight:1920 removing all the brackets and quote marks.

Is this possible.

Many thanks for your time.

Answer Source

You need to JSON.parse() then access keys, values normally.

See below example:

result = JSON.parse(result);
$('#size').html("DisplayWidth: " + result["imagesizes"][0]["DisplayWidth"] 
            + ", DisplayWidth: " + result["imagesizes"][0]["DisplayWidth"]).show();