我想搜索一个Javascript对象的所有elemetns,并替换文本“???”的每一个出现。比如说,“***”。查找并替换JSON对象元素中的文本?
的JSON的一个例子是
{
"page-title": "Tasks",
"sections": [{
"section-heading": "Work",
"subsections": [{
"subsection-heading": "First",
"subsection-texts": [{
"text": "This is some text."
}]
}, {
"subsection-heading": "Second",
"subsection-texts": [{
"text": "This is some more text."
}, {
"text": "This is even more text ???."
}]
}, {
"subsection-heading": "Third ???",
"subsection-texts": [{
"text": "This is the last text."
}]
}]
}]
}
正如你所看到的, “???”文本可能处于不同的级别。那么是否有某种方法可以用“***”来搜索和替换每个$ ??? $?
我正在寻找一种方法,将检查实际的JSON对象元素,我不想要一个方法,然后使用正则表达式的字符串对象。这可以有效地完成吗?
JSON对象是用词不当。你的意思是一个JavaScript对象或JSON字符串? – trincot
@trincot确定我已将它更改为Javascript对象。 – sonicboom