我的json.parse不能正常工作 [英] My json.parse not working fine

查看:63
本文介绍了我的json.parse不能正常工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

<!DOCTYPE html>
<html>
<head>
<script>
function input(){
   var sResult = '[{"urlName":"ChiroTouch-Accounting-Maintenance","summary":"The maintenance section of the Accounting ribbon allows you to configure site information, providers, payment sources, payers, and trading partners.","label":"ChiroTouch Accounting Maintenance","id":"kA163000000CaXFCA0"},{"urlName":"ChiroTouch-Accounting-Maintenance-Payment-Sources","summary":"When you receive a payment from your payors (such as Aetna, BCBS, etc.) the Accounting application allows you to apply this payment to the patients in the system associated with this payor.","label":"ChiroTouch Accounting Maintenance: Payment Sources","id":"kA163000000CaXACA0"},{"urlName":"ChiroTouch-Meaningful-Use","summary":null,"label":"ChiroTouch Meaningful Use","id":"kA163000000CaXPCA0"},{"urlName":"ChiroTouch-Provider-All-In-One-Toolbar-Overview","summary":"When you first log in to the application, the main screen appears blank. The screen is not yet populated with a patient’s information because you have not yet selected a patient or attempted to call the next patient to the room. However, you do have access to most of the toolbar options located at the top of the screen.","label":"ChiroTouch Provider All-In-One Toolbar Overview","id":"kA163000000CaXjCAK"},{"urlName":"ChiroTouch-Provider-All-In-One-Treatment-Plans","summary":"The Treatment Plan section allows you to create and manage your patient’s treatment plan. Various areas in this section allow you to create and modify your current plan, request an appointment and view the patient’s appointment history.","label":"ChiroTouch Provider All-In-One Treatment Plans","id":"kA163000000CaXoCAK"},{"urlName":"ChiroTouch-Provider-Charges-SALT","summary":null,"label":"ChiroTouch Provider: Charges: SALT","id":"kA163000000CaXZCA0"},{"urlName":"ChiroTouch-Provider-Configuring-Your-Treatment-Notes","summary":"Your Treatment Notes are configurable so that you can set up your treatment note headings in the way that works best for you. To configure yourTreatment Notes setup, click the \"Setup\" button in the lower right-hand corner of the Treatment Notes screen.","label":"ChiroTouch Provider: Configuring Your Treatment Notes","id":"kA163000000CaXeCAK"},{"urlName":"ChiroTouch-Provider-Treatment-Notes","summary":"To enter treatment notes for your patients, click the \"Tx Notes\" button on the Patient Search screen.","label":"ChiroTouch Provider: Treatment Notes","id":"kA163000000CaXUCA0"}]';


console.log('sResult'+'-->' + sResult);
   
	

	
	
	var text1 = JSON.parse(sResult);
	document.forms.form1.area.value = text1;
	}
  
</script>
</head>
<body>
<form name='form1'>
    
    <textarea name='area' rows="12" cols="100" ></textarea>
	
	<input onclick='input()' type='button' value='BUTTON' id='button'>
	

</form>
</body>
</html>





我的尝试:



当我们再添加一个'\'时,它就可以了。但是如果我们删除一个,那就不行了



What I have tried:

when we add one more '\' ,then it is work fine.but if we remove one,then it is not work

推荐答案

在Javascript中,当你写下文字字符串:

In Javascript, when you write the literal string:
var s = 'click the \"Setup\" button';



您创建一个包含的字符串:


you create a string that contains:

click the "Setup" button





当你通过时字符串到 JSON.parse ,它将第一个视为字符串的结尾。然后它会看到} ,因为它已达到属性值的末尾,而是它找到标识符设置



你必须逃避 \ 字符,以便它包含在传递给 JSON.parse 的字符串中:



When you pass that string to JSON.parse, it sees the first " as the end of the string. It's then expecting to see a , or a }, as it's reached the end of the property value, but instead it finds the identifier Setup.

You have to escape the \ character so that it's included in the string passed to JSON.parse:

var s = 'click the \\"Setup\\" button';


这篇关于我的json.parse不能正常工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆