如果密钥包含“。”,如何在JS中解析JSON。字符

时间:2018-01-28 16:22:50

标签: javascript arrays json

[  
   {  
      "s.no":0,
      "amt.pledged":15823,
      "blurb":"'Catalysts, Explorers & Secret Keepers: Women of Science Fiction' is a take-home exhibit & anthology by the Museum of Science Fiction.",
      "by":"Museum of Science Fiction",
      "country":"US",

我想访问一个json对象的元素,其中键包含'。'在Javascript In this image the "s.no" contains '.' so how can i access the value of "s.no"

2 个答案:

答案 0 :(得分:1)

您可以在解析后使用myObj["s.no"]

答案 1 :(得分:0)

使用方括号([]),如下所示:

var data = [{  
    "s.no":0,
    "amt.pledged":15823,
    "blurb":"'Catalysts, Explorers & Secret Keepers: Women of Science Fiction' is a take-home exhibit & anthology by the Museum of Science Fiction.",
    "by":"Museum of Science Fiction",
    "country":"US"
  }];
var slNo = data[0]["s.no"];
console.log(slNo);