Want to know javascript convert json string to object? we have a huge selection of javascript convert json string to object information on alibabacloud.com
result is already a json object. You only need to call this object directly. Here, $. the getJSON method is used as an example to describe the data processing method:
The Code is as follows:
$. GetJSON ("http://blog.snsgou.com/", {param: "snsgou"}, function (data ){// The returned data is already a json
Converts a json string to a json object. During data transmission, json is transmitted in the form of text, that is, strings, while JS operates on JSON objects. Therefore, mutual conversion between
This article describes how to convert a json object to a string. For more information, see
The Code is as follows:
/*Converts a json object to a string.Usage:Var json = {id = 3, name
Copy codeThe Code is as follows: function obj2str (o ){
Var r = [];
If (typeof o = "string") return "\" "+ o. replace (/([\ '\ "\])/g," \ $1 "). replace (/(\ n)/g, "\ n "). replace (/(\ r)/g, "\ r "). replace (/(\ t)/g, "\ t") + "\"";
If (typeof o = "object "){
If (! O. sort ){
For (var I in o)
R. push (I + ":" + obj2str (o [I]);
If (!! Document. all ! /^ \ N? Function \ s * toString \ (\) \ s * \ {\
Copy codeThe Code is as follows:Function obj2str (o ){Var r = [];If (typeof o = "string") return "\" "+ o. replace (/([\ '\ "\])/g," \ $1 "). replace (/(\ n)/g, "\ n "). replace (/(\ r)/g, "\ r "). replace (/(\ t)/g, "\ t") + "\"";If (typeof o = "object "){If (! O. sort ){For (var I in o)R. push (I + ":" + obj2str (o [I]);If (!! Document. all ! /^ \ N? Function \ s * toString \ (\) \ s * \ {\ n? \ S * \ [na
This article mainly introduces the best way to convert JSON strings into JSON objects in JS, and need friends to refer to the following In JS, the JSON string is parsed into JSON data format, usually in two ways: 1. One is to us
Converts a json string to a json object. During data transmission, json is transmitted in the form of text, that is, strings, while JS operates on JSON objects. Therefore, the conversion between
to the eval () function is JS own, the other several methods are from the Json.js package. The new version of JSON modifies the API to inject json.stringify () and Json.parse () two methods into the Javascript built-in object, which becomes the object.tojsonstring (), and the latter becomes the Strin G.parsejson (). If you are prompted not to find the tojsonstri
scripts), which can easily cause system security problems. So you can use some third-party client script libraries that circumvent eval (), such as JSON in JavaScript, which provides a script library of no more than 3k.The second parsing method: Using the Function object to complete, its typical application is in jquery in the Ajax method of success and so on th
: ' Yulin '}, {name: ' 6109 ', V Alue: ' Ankang '}, {name: ' 6110 ', Value: ' Shangluo '} ]}";This is based on the data type obtained by jquery asynchronously,--json object and string, and describes how the results are handled in two ways. 1, for the JSON string
the data type obtained asynchronously by jQuery-json object and string, we will introduce the Processing Methods of the obtained results in two ways.1. For the JSON string returned by the server, if jQuery asynchronous requests do not provide a type description or are accep
For example:JSON string:VarJSON object:var str2 = {"Name": "Cxh", "Sex": "Man"};One, JSON string converted to JSON objectTo use the above str1, you must first convert to a JSON object using the following method:Convert from
For example:JSON string:var str1 = ' {' name ': ' cxh ', ' sex ': ' Man '} ';JSON object:var str2 = {"Name": "Cxh", "Sex": "Man"};One, JSON string converted to JSON objectTo use the above str1, you must first convert to a JSON
For example:JSON string:var str1 = ' {' name ': ' cxh ', ' sex ': ' Man '} ';JSON object:var str2 = {"Name": "Cxh", "Sex": "Man"};One, JSON string converted to JSON objectTo use the above str1, you must first convert to a JSON
For example:JSON string:var str1 = ' {' name ': ' cxh ', ' sex ': ' Man '} ';JSON object:var str2 = {"Name": "Cxh", "Sex": "Man"};One, JSON string converted to JSON objectTo use the above str1, you must first convert to a JSON
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.