0

I'm trying to see if there is a way for me to parse a json object that has a space in it. Below is a sample of what the json looks like:

[
    {"Search Engine":"Google","Keywords":"air conditioning Altamonte Springs FL"},
    {"Search Engine":"Google","Keywords":"air conditioning Apopka FL"}
]

Below is the JavaScript I'm using to parse the data

jQuery.ajax({
    url: '<?php echo plugins_url('CSAnalytics/csv-json/csv-converter.php'); ?>',
    dataType: 'json',
    success: function (response) {
        var searchHTML = '';
        jQuery.each(response, function (i, item) {
            searchHTML += '<tr><td class="tg-yw4l">' + item.Search Engine + '</td><td class="tg-yw4l">' + item.Keywords + '</td><td class="tg-yw4l">' + item.Website + '</td><td class="tg-yw4l">' + item.Position + '</td><td class="tg-yw4l">' + item.Previous + '</td><td class="tg-yw4l">' + item.Change + '</td><td class="tg-yw4l">' + item.Page + '</td><td class="tg-yw4l">' + item.Best + '</td></tr>';
        });
        jQuery('#search_ranking').append(searchHTML);
    }
});

I cannot figure out how to parse the data out for "Search Engine" because it has that space in it.

krillgar
  • 12,596
  • 6
  • 50
  • 86
Phantom
  • 108
  • 10

1 Answers1

0

I didn't try this, but:

item['Search Engine']

Should do you just fine. Object properties can be referenced like that with javascript objects. This would also be a way to use a variable to reference something:

var variable = 'Search Engine';

item[variable]
Mark
  • 861
  • 9
  • 17