我可以将字符串“['A',' B','C']”创建为列表吗?JavaScript

tcomlyy6  于 2023-01-29  发布在  Java
关注(0)|答案(1)|浏览(148)

所以我用JavaScript做了一个Renissance的Freckle hack,我检索了JSON base64,并使用atob()函数对其进行了解码,在那里您可以得到答案,但我只是想知道我是否可以生成解码后的字符串:“['A','B','C']”(正确答案)添加到不包括'[]'和','的列表中。

async function getAnswer(){
    var id = document.getElementsByClassName("math-question__wrapper___iRtlD")[0]["dataset"]["questionId"];
    var response = await fetch("https://api.freckle.com/2/math/questions/"+id+"?lang=en", {
      method: "GET",
    
      headers: {
        "Content-type": "application/json; charset=UTF-8"
      }
    });

    
    json = await response.json();
    var answer=json["obfuscated-correct-answers"];
    if (typeof answer == "undefined") {
        answer=json['obfuscated-fill-in-the-blanks-correct-answers'];
    }

    
    var final=atob(answer);
    console.log(final);
}
getAnswer();
92dk7w1h

92dk7w1h1#

base 64字符串解码为有效的JSON,因此在调用atob()之后使用JSON.parse()

async function getAnswer() {
  var id = document.getElementsByClassName("math-question__wrapper___iRtlD")[0]["dataset"]["questionId"];
  var response = await fetch("https://api.freckle.com/2/math/questions/" + id + "?lang=en", {
    method: "GET",

    headers: {
      "Content-type": "application/json; charset=UTF-8"
    }
  });

  json = await response.json();
  var answer = json["obfuscated-correct-answers"];
  if (typeof answer == "undefined") {
    answer = json['obfuscated-fill-in-the-blanks-correct-answers'];
  }

  var final = JSON.parse(atob(answer));
  console.log(final);
}
getAnswer();

相关问题