Alibabacloud.com offers a wide variety of articles about javascript json parse example, easily find your javascript json parse example information here online.
': ' m ', ' Age ': ' '}, {' Name ":" McGrady "," Sex ":" M "," Age ":" 27 "}]}] ';
We can use the Eval () function to invoke the JavaScript compiler to turn JSON text into objects. Because JSON is an exact subset of JavaScript, the compiler can parse the
the object into a JSON string. The old version of the browser does not support this object, but you can do the same with Json2.js. If you don't understand, don't worry, take a look at the example://This is a JSON string, such as getting string information from ajax var my_json_string = ' {"Prop": "Val"} '; Deserializes a string into an object var my_obj = Json.p
The method used for parsing is generally eval or new function. Currently, IE8 and Firefox3.1 have built-in native JSON objects (it is said that there will be a certain performance improvement ). In actual use, how can we choose from these three methods (because of performance problems, do not consider using javascript to implement parsing? In the face of a large number of browsers, which method of performan
. convert a JSON string to a JSON object To use str1 above, you must use the following to convert to a JSON object first:// Converts a JSON string to a JSON objectCopy codeThe Code is as follows:Var obj = eval ('+ str + ')'); OrCopy codeThe Code is as follows:Var obj = str.
syntax exception is thrown ).2. You can use tojsonstring () or the global essentials JSON. stringify () to convert a JSON object to a JSON string.Example: www.2cto.comVaR last = obj. tojsonstring (); // converts a JSON object to a JSON characterOrVaR last =
Recently tried to use ExtJS to show the tree menu. It took a really hard time. The menu items in the tree menu need to be loaded dynamically, while the current version of ExtJS only supports JSON-formatted data. After checking some information, I decided to use Struts2 's json-plugin. First, according to the example to do a, but the result is not successful, the
This time in the project before and after the data interaction using the JSON, after this period of use, probably understand, a simple summary of JSON.
Json:javascript Object Notation (JavaScript object notation).
JSON is the syntax for storing and exchanging text information. Like XML.
parseJSON () is used () after the function is processed, there will be questions (a syntax exception is thrown ).2. You can use toJSONString () or the global essentials JSON. stringify () to convert a JSON object to a JSON string.For example:Var last = obj. toJSONString (); // converts a JSON object to a
+ ")")The purpose of parentheses is to force the eval function to forcibly convert the expressions in the brackets into objects when evaluating JavaScript code, rather than being executed as statements. For example, if the object literal quantity {} is not properly added with outer brackets, eval will mark the braces as the beginning and end of the JavaScript co
; Array ([0] => stdClass Object ([name] => Array ([0] => stdClass Object ([chen] => chenling [ling] => chenli )) [sex] => male [age] => 25) [1] => stdClass Object ([name] => sun [sex] => Female [age] => 24 )))*/
For example, if you want to obtain the element whose value is chenling, you should access it as follows:
$ J-> item1 [0]-> name [0]-> chen; // This will get the value of the element chen: chenling
In fact, this access method combines object an
Objective
The purpose of this article is to often see developers say: To convert the string into a JSON object, the JSON object into a string, and other similar topics, so the previous collection of a foreigner's article in the translation of the text for everyone to discuss, if there is a mistake, please point out, thank you.
Body
The subject of this article is based on ecmascript262-3, and the 262-5 new
);The key point is this statement: var jsoncitys = Json.parse (opts); Json.parse () is the 1 API provided by JavaScript, which is the function of converting a JSON-formatted string into a JSON object. Of course, if the string passed in is a string of array styles composed of multiple JSON-formatted objects, as we have
are mutually independent entities.Var jack = new Person ('jack', 26, new Address ('qing Hai Road ', 123 ));Var abruzzi = new Person ('abruzzi', 26 );// View the resultPrint (jack. getName ());Print (jack. getAge ());Print (jack. getAddr ());Print (abruzzi. getName ());Print (abruzzi. getAge ());Print (abruzzi. getAddr ()); The running result is as follows:Jack26Street: Qing Hai Road, No: 123Abruzzi26Street: Huang Quan Road, No: 135JSON and usageJSON is called
following two execution results are different:Alert (eval ("{}");//return undefinedAlert (eval ("({})");//return Object[object]2. For the JSON string returned by the server, if the jquery asynchronous request sets the type (typically this configuration property) to "JSON", or uses the $.getjson () method to get the server back, then the eval () method is not required., because the result is already a
; StdClass object ( [ Name] => Array ( [0] => stdClass Object ( [Chen] => chenling [Ling] => Chenli ) ) [sex] => man [age] => ) [ 1] => stdClass Object ( [name] => Sun [sex] => female [age] => ) )
For example, if I'm going to get the element that the value is chenling, you should access it like this:$J->item1[0]->name[0]->chen;//This will get the element Chen's value: chenlingIn fact, this form of access combines th
JSON is the native format of JavaScript, which means that processing JSON data in JavaScript does not require any special APIs or toolkits.
JSON syntax
JSON is constructed in two structures:
Object-A collection of name/value pa
JSON(JavaScript Object Notation) is a lightweight data exchange format. Easy to read and write. It is also easy to parse and generate machines. It is based on a subset of JavaScript programming language, standard ECMA-262 3rd edition-December 1999. JSON uses a completely lan
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.