How to get JSON Key and Value?

后端 未结 3 1997
日久生厌
日久生厌 2021-01-30 08:28

I have written following code to get JSON result from webservice.

function SaveUploadedDataInDB(fileName) {
            $.ajax({
                type: \"POST\",
         


        
3条回答
  •  一个人的身影
    2021-01-30 09:09

    It looks like you're getting back an array. If it's always going to consist of just one element, you could do this (yes, it's pretty much the same thing as Tomalak's answer):

    $.each(result[0], function(key, value){
        console.log(key, value);
    });
    

    If you might have more than one element and you'd like to iterate over them all, you could nest $.each():

    $.each(result, function(key, value){
        $.each(value, function(key, value){
            console.log(key, value);
        });
    });
    

提交回复
热议问题