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!