Js custom in the character string into json

Js string will be converted from the format defined for json

Let me talk about my problems, I am going to write an epidemic analysis chart, the source data is obtained from the interface, his data type must be json format, if it is their direct splicing Json string can not be used as a data source of the chart
Here Insert Picture Description
conversion method

		//先将字符串拼接成JSON
		var date1="[{\"name\":\"现有确诊\",\"value\":\""+confirmedCount+"\"},{\"name\":\"现有治愈\",\"value\":\""+curedCount+"\"},{\"name\":\"现有死亡\",\"value\":\""+deadCount+"\"}]";
		//然后使用eval函数,注意中间的两个单引号
		var date2=eval('(' + date1 + ')');
Published 12 original articles · won praise 17 · views 2981

Guess you like

Origin blog.csdn.net/qq1140037586/article/details/105269408