jQuery looping .each() JSON key/value not working

后端 未结 2 790
情话喂你
情话喂你 2020-12-13 06:21

I am having problems in looping the key/value of JSON by jQuery .each() function

Initially I have a JSON like this:

json = {\"aaa\":[
              {         


        
相关标签:
2条回答
  • 2020-12-13 06:57

    Since you have an object, not a jQuery wrapper, you need to use a different variant of $.each()

    $.each(json, function (key, data) {
        console.log(key)
        $.each(data, function (index, data) {
            console.log('index', data)
        })
    })
    

    Demo: Fiddle

    0 讨论(0)
  • 2020-12-13 07:00

    With a simple JSON object, you don't need jQuery:

    for (var i in json) {
       for (var j in json[i]) {
         console.log(json[i][j]);
       }
    }
    
    0 讨论(0)
提交回复
热议问题