Json data processing and data binding and json Data Processing binding

Source: Internet
Author: User

Json data processing and data binding and json Data Processing binding

I. json Data Processing

1. json data

{"Img": "quizvault_internet_test_banner@2x.png", "golds": "200", "praise": "64000", "tit": "The trouble the Internet brings to work ", "tit_describe": "The body is hollowed out in the circle of friends, and HR will talk to you affectionately: leave without doing anything. What are your situations? "," Images ": [{" name ":" quizvault_internet_test_nor.png "},{" name ":" quizvault_internet_test_nor.png "},{" name ":" success "}, {"name": "quizvault_internet_test_nor.png"}], "images_tit": [{"name": "24-hour standby since you are used to work" },{ "name ": "24-hour standby since everyone gets used to work" },{ "name": "24-hour standby since everyone gets used to work" },{ "name ": "standby 24 hours since everyone gets used to work"}]}

2. Get Data

Data injection: "{data }}"

3. Data Processing:

var datas = "{{data}}";   var data;   srtjson(datas);   console.log(data);   function srtjson(datas) {    var b = htmlDecode(datas);    var dataObj = b.substring(1, b.length - 1);    data = eval("(" + dataObj + ")");    function htmlDecode(text) {     var temp = document.createElement("div");     temp.innerHTML = text;     var output = temp.innerText || temp.textContent;     temp = null;     return output;    }   }

4. Data Binding

// Set the json key to id and bind data to for (var p in data) {values ('{'{p}.html (data [p]) by traversing the object;};
// Cyclically binds the array and dynamically converts it into html for (var I = 0; I <data. question_tit.length; I ++) {$ ('# J_main ul '). append ('<li> <div class = "cir">' + data. question_tit [I]. name + '</div> <span>' + data. question_main [I]. name + '</span> </li> ');}
// Bind dynamic css ('.banner'hangzhou.css ({'backgroundage': 'url ('+ 'images/' + data. img + ')' // 'backgroundage': 'url ('+' {resource} '+ data. img + '? Type = web-image' + ')'});

The above is all the content of this article. I hope this article will help you in your study or work. I also hope to provide more support to the customer's home!

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.