JSON parameter that includes whitespace

An XMLHTTPRequest is failing to run, because of what looks like a problem with there being whitespace in some of the JSON parameters requests.

The requests in the 4th & 5th lines of code below are an example of the syntax with and without space.

function procReq(e) { 
    if (APIXHR.readyState == 4 && APIXHR.status == 200)     { 
    var resp = JSON.parse(APIXHR.responseText);         
    var Home = resp.data.game.TeamA_TeamB.Teams[0];    /// THIS WORKS 
    var Away = resp.data.game.Te amC_TeamD.Teams[1];    /// THIS DOESN'T
    document.getElementById("Home").innerHTML = Home;
    document.getElementById("Home").style.textTransform = "uppercase";
    document.getElementById("Away").innerHTML = Away;

Not sure if I'm missing a Regex to correct the syntax.

The function runs fine for those requests without the whitespace.

1 answer

  • answered 2017-12-15 20:38 Sun


    var Away = resp.data.game["Te amC_TeamD"].Teams[1];


    var o = {
      "ke y": "value"
    console.log(o["ke y"]);
    //console.log(o.ke y); // It doesn't work!