Loop through JSON object List

后端 未结 8 2002
忘掉有多难
忘掉有多难 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:25

    This will work!

    $(document).ready(function ()
        {
            $.ajax(
                {
                type: 'POST',
                url: "/Home/MethodName",
                success: function (data) {
                    //data is the string that the method returns in a json format, but in string
                    var jsonData = JSON.parse(data); //This converts the string to json
    
                    for (var i = 0; i < jsonData.length; i++) //The json object has lenght
                    {
                        var object = jsonData[i]; //You are in the current object
                        $('#olListId').append('
  • The main thing about this is using the property exactly the same as the attribute of the JSON key-value pair.

提交回复
热议问题