简体   繁体   English

JSON字符串转义 - MathJax

[英]JSON String Escaping - MathJax

I am trying to figure out how to have JS encode my MathJax string. 我试图弄清楚如何让JS编码我的MathJax字符串。 Let's say I have: 比方说我有:

\(ax^2 + bx + c = 0\)

This fails a JSON lint test, but is the valid code I would use to make the equation appear inline. 这无法进行JSON lint测试,但是我将用于使等式显示为内联的有效代码。 Is there any built in method to do this in JS? 在JS中有没有内置的方法来做到这一点?

componentURIEncode()

Is not giving an appropriate solution. 没有给出适当的解决方案。

First, you can't have single backslashes in a JavaScript string. 首先,JavaScript字符串中不能包含单个反斜杠。

Second, If you want to JSON encode an object, you need an object: 其次,如果要对对象进行JSON编码,则需要一个对象:

var MyMath = {};

MyMath.formula = "\\(ax^2 + bx + c = 0\\)";

var jMath = JSON.stringify(MyMath);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM