Javascript: Jquery each loop with json array or object, jqueryjson

Source: Internet
Author: User

Javascript: Jquery each loop with json array or object, jqueryjson

Json:

{ "justIn": [{ "textId": "123", "text": "Hello,geovindu", "textType": "Greeting" },{ "textId": "514", "text":"What's up?", "textType": "Question" },{ "textId": "122", "text":"Come over here", "textType": "Order" }],"recent": [{ "textId": "1255", "text": "Hello,sibodu", "textType": "Greeting" },{ "textId": "6564", "text":"What's up?", "textType": "Question" },{ "textId": "0192", "text":"Come over here", "textType": "Order" }],"old": [{ "textId": "5213", "text": "Hello,geovindu", "textType": "Greeting" },{ "textId": "9758", "text":"What's up?", "textType": "Question" },{ "textId": "7655", "text":"Come over here", "textType": "Order" }]}

  

<script src="Scripts/jquery-1.9.1.min.js" type="text/javascript"></script> <script type="text/javascript">    $(document).ready(function () {        $("#Link").click(function () {            $.ajax({                type: "GET",                url: "jsonfile/5.json",                dataType: "json",                success: function (data) {                    $.each(data, function (k, v) {                        $("#mapinfo").append(k + ', ' + "<br/>

Json:

{"District": [{"did": "1", "name": "Wuchang district", "communitys": {"community": [{"cid ": "21", "name": "Anshun jiayuan", "url": "asjy", "address": "23 zhongbei Road, Wuchang District", "x": "114.33830023 ", "y": "30.55309607", "img": "com21.png", "hot": "0", "groupbuy": "0", "estates ": {"estate": [{"name": "zhuju", "value": "Z" },{ "name": "Mei Ling", "value ": "M" },{ "name": "Lanting", "value": "L" },{ "name": "jufang", "value ": "J"}] },{ "cid": "25", "name": "bury central living area", "url": "brj", "address ": "No. 586, Wuchang Wuyi road", "x": "114.33729172", "y": "30.52570714", "img": "com25.png", "hot": "0 ", "groupbuy": "0", "estates": {"estate": [{"name": "nanyi district", "value": "S "}, {"name": "beiyi district", "value": "N" },{ "name": "dong'er district", "value": "E "}, {"name": "Second West District", "value": "W"}]},

  

<Title> json jquery traversal json object array geovindu </title> <script src = "Scripts/jquery-1.9.1.min.js" type = "text/javascript"> </script> <script type =" text/javascript "> // object syntax JSON data format (when the server calls back the object data format is json data format, the JSON format must be guaranteed. The callback Object must be converted using the eval function (otherwise, the Object will not be obtained ). This article does not detail the server-side callback data. We will directly customize the object) $ (document ). ready (function () {$ ('# button '). click (function () {$. ajax ({type: "GET", url: "jsonfile/4. json ", dataType:" json ", success: function (data) {// var obj = eval (data. district); $ (data. district ). each (function (index, value) {// var val = obj [index]; $ ("# title "). append (index); $. each (value, function (k1, v1) {$ ("# content "). append (k1 + ''+ v1 +" </div> 

How to select json item from the array

<Title> json jquery traversal parsing json object How to select json item from the array </title> <script src = "Scripts/jquery-1.9.1.min.js" type = "text/javascript"> </ script> <script type = "text/javascript"> // http://stackoverflow.com/questions/6107039/how-to-select-json-item-from-the-array//http://stackoverflow.com/questions/4992383/use-jquerys-find-on-json-objectvar JSON = {"infos": {"info": [{"startYear": "1900", "endYear": "1930", "timeZoneDesc": "geovindu .. "," timeZoneID ":" 1 "," note ": {" notes ": [{" id ":" 1 "," title ":" Mmm "}, {"id": "2", "title": "Wmm" },{ "id": "3", "title": "Smm"}]}, "links": [{"id": "1", "title": "Red House", "url ":" http://infopedia.nl.sg/articles/SIP_611_2004-12-24.html "},{" Id ":" 2 "," title ":" Joo Chiat "," url ":" http://www.the-inncrowd.com/joochiat.htm "},{" Id ":" 3 "," title ":" Bake "," url ":" https://thelongnwindingroad.wordpress.com/tag/red-house-bakery "}] }}; Var infoLength = JSON.infos.info. length; for (infoIndex = 0; infoIndex <infoLength; infoIndex ++) {var notesLength = JSON.infos.info [infoIndex]. note. notes. length; for (noteIndex = 0; noteIndex <notesLength; noteIndex ++) {alert (JSON.infos.info [infoIndex]. note. notes [noteIndex]. title) ;}}</script>

  

Related Article

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.