最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - String replace values recursively in json - Stack Overflow

programmeradmin0浏览0评论

I have a json object such as:

var json = {
    "title": "Math Symbols: ¬",
    "sections": [
        "The ¬ symbol",
        "¬ and y"       
    ]
};

I need to replace all instances of the "¬" character with something that looks like the Mathematical symbol for x: sample.

Side note: I can't use that actual symbol (html entity &#119909;) because the Arial font i'm using doesn't support it. So I was planning on replacing "¬" with <span class="math">x</span> and styling the math class with Times New Roman & italic.

I can't change the Arial Font, and I don't need any other Math symbols - MathML support or the like isn't necessary.

Something like this would be ideal:

json = json.replace("¬", "<span class='math'>x</span>");

I have a json object such as:

var json = {
    "title": "Math Symbols: ¬",
    "sections": [
        "The ¬ symbol",
        "¬ and y"       
    ]
};

I need to replace all instances of the "¬" character with something that looks like the Mathematical symbol for x: sample.

Side note: I can't use that actual symbol (html entity &#119909;) because the Arial font i'm using doesn't support it. So I was planning on replacing "¬" with <span class="math">x</span> and styling the math class with Times New Roman & italic.

I can't change the Arial Font, and I don't need any other Math symbols - MathML support or the like isn't necessary.

Something like this would be ideal:

json = json.replace("¬", "<span class='math'>x</span>");
Share Improve this question asked Aug 19, 2013 at 10:24 aaronjbaptisteaaronjbaptiste 5544 silver badges14 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 11

This converts the JSON into string

JSON.stringify(json).replace(/¬/g, "<span class='math'>x</span>")

and then you could convert it back to JSON

JSON.parse(json)
发布评论

评论列表(0)

  1. 暂无评论