Detailed JSON data format simple parsing

Source: Internet
Author: User
Tags eval

1,json data format

The code is as follows Copy Code

Background program return string

{' message ': ' Hello word '}

The front desk resolves this

var dictionary=eval ("(" + Data + ")");

Background program return string

({' message ': ' Hello word '})

The front desk resolves this

var dictionary=eval (data);

$.ajax ({
URL: "Getjosnstring",
Type: "Post",
DataType: "JSON",
Success:function (data) {
var msg = eval (data);
alert (msg.message); Output the result Hello word
}
});

2.each Loop Object json

Background definition string

The code is as follows Copy Code

({' message ': ' Hello word ', ' Msg ': ' Hello word '})

({' Items ': [{' message ': ' Hello word ', ' Msg ': ' Hello word '}]}

$.ajax ({
URL: "Getjosneach",
Type: "Post",
DataType: "JSON",
Success:function (data) {
var datas = eval (data);

/*********** first read the dictionary type ***************
$.each (datas, function (key, value) {
Alert (key + ":" + value); Message:hello Word

});

*************************/

The second method of parsing a string

$.each (datas. Items, function (key, value) {
Alert (key + ":" + value. MSG); 0:hello the first element and value in a word value
});
}
});

Above also casually introduced jquery each object everybody is interested can look for oneself, here only is simple uses

Contact Us

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.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.