Loop through JSON object List

后端 未结 8 1971
忘掉有多难
忘掉有多难 2020-11-28 20:51

I am returning a List<> from a webservice as a List of JSON objects. I am trying to use a for loop to iterate through the list and grab the values out of the properties.

相关标签:
8条回答
  • 2020-11-28 21:29

    Since you are using jQuery, you might as well use the each method... Also, it seems like everything is a value of the property 'd' in this JS Object [Notation].

    $.each(result.d,function(i) {
        // In case there are several values in the array 'd'
        $.each(this,function(j) {
            // Apparently doesn't work...
            alert(this.EmployeeName);
            // What about this?
            alert(result.d[i][j]['EmployeeName']);
            // Or this?
            alert(result.d[i][j].EmployeeName);
        });
    });
    

    That should work. if not, then maybe you can give us a longer example of the JSON.

    Edit: If none of this stuff works then I'm starting to think there might be something wrong with the syntax of your JSON.

    0 讨论(0)
  • 2020-11-28 21:31

    had same problem today, Your topic helped me so here goes solution ;)

     alert(result.d[0].EmployeeTitle);
    
    0 讨论(0)
提交回复
热议问题