Home >Web Front-end >JS Tutorial >Issues you need to pay attention to when converting text into JSON objects with JQuery_jquery

Issues you need to pay attention to when converting text into JSON objects with JQuery_jquery

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOriginal
2016-05-16 18:06:52951browse

1) The $.parseJSON method returns a string, not a JSON object.

2) To convert a string into an object, it is easy to think of the eval method in JS. In fact, it is possible, but you need to add parentheses. Such as var js="{"PageIndex":"1"}";var obj=eval("(" js ")");. However, using eval is unsafe because it can compile any js code.

3) Download a JSON parser, because it only recognizes JSON text. This is safer. The JSON official website provides such a script. Address: http://www.JSON.org/json2.js. It is relatively simple to use. After introducing the file, such as: JSON.parse($("#ctl00_ContentPlaceHolder1_hfSearch").val().toString()).

4) When using the JSON.parse method or the $.parseJSON method, note that the name and value of the JSON data are enclosed in double quotes. For the $.parseJSON method, the JSON string must be enclosed in single quotes. Up and then convert, for the JSON.parse method, it is not necessary. What a fucking waste of time.

Pay attention to these tips to avoid many detours when operating JSON data.

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn