Javascript 有没有一种方法可以在JSON对象字符串化后替换它的文本?
我有一些JSON数据,其中包含一些URL。我通过循环对象从json中提取这些URL,效果很好。然而,URL有“page:”预先挂起,我正试图用“https://”替换它们 我不能让replace属性工作,每次都给我相同的结果 我尝试以不同的方式使用replace()属性,并使用console.log查看结果。我还尝试将JSON字符串化,因为我听说这是处理JSON的一件好事 每次我看到“页面”这个词时,它都没有被替换Javascript 有没有一种方法可以在JSON对象字符串化后替换它的文本?,javascript,json,stringify,Javascript,Json,Stringify,我有一些JSON数据,其中包含一些URL。我通过循环对象从json中提取这些URL,效果很好。然而,URL有“page:”预先挂起,我正试图用“https://”替换它们 我不能让replace属性工作,每次都给我相同的结果 我尝试以不同的方式使用replace()属性,并使用console.log查看结果。我还尝试将JSON字符串化,因为我听说这是处理JSON的一件好事 每次我看到“页面”这个词时,它都没有被替换 function showTopArticles(jsonObj) { var
function showTopArticles(jsonObj) {
var getEntries = jsonObj.feed.entry;
var stringified = JSON.stringify(getEntries);
console.log(getEntries);
for (var i = 0; i < getEntries.length; i++) {
var list = document.createElement('article');
var articleTitle = document.createElement('li');
var articleUrl = document.createElement('a');
articleTitle.textContent = getEntries[i].title.$t;
articleUrl.textContent = getEntries[i].content.$t;
articleUrl.textContent.replace("page: ", "https://");
console.log(articleUrl.textContent);
list.appendChild(articleTitle)+list.appendChild(articleUrl);
section.appendChild(list);
}
}
函数showTopArticles(jsonObj){
var getEntries=jsonObj.feed.entry;
var stringified=JSON.stringify(getEntries);
console.log(getEntries);
对于(var i=0;i
我希望输出url为“”,但我看到的是“page:www.google.com”replace()
返回一个修改后的值,它不会修改原始字符串
你想要的是:
articleUrl.textContent = articleUrl.textContent.replace("page: ", "https://");