我有一个 JSON 对象,其中包含大约 150 个表单条目,[key] : [sentence]
其中句子通常一遍又一遍地包含相同的文本。例如:
var test = {
"abc" : "This is the first sentence that is in this JSON object. Hello! Blue."
"abd" : "Red. This is the second sentence that is in this JSON object. Hi!"
"abe" : "This is the third sentence that is in this JSON object. Hey! Yellow."
"abf" : "White. This is the fourte sentence that is in this JSON object. Hola!"
}
您可以看到字符串“此 JSON 对象中的句子”。经常重复。用某个锚点替换它然后在我从对象中获取条目后替换锚点会更有效吗?那是:
var test = {
"abc" : "This is the first #anchor# Hello!"
"abd" : "This is the second #anchor# Hi!"
"abe" : "This is the third #anchor# Hey!"
"abf" : "This is the fourte #anchor# Hola!"
}
var anchor = "sentence that is in this JSON object."
从 JSON 中获取所需值后,将字符串替换为实际文本?这些句子没有特定的模式,但其中大量包含重复的文本字符串。感谢您的建议!