How to get JSON Key and Value?

后端 未结 3 1992
日久生厌
日久生厌 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:34

    First, I see you're using an explicit $.parseJSON(). If that's because you're manually serializing JSON on the server-side, don't. ASP.NET will automatically JSON-serialize your method's return value and jQuery will automatically deserialize it for you too.

    To iterate through the first item in the array you've got there, use code like this:

    var firstItem = response.d[0];
    
    for(key in firstItem) {
      console.log(key + ':' + firstItem[key]);
    }
    

    If there's more than one item (it's hard to tell from that screenshot), then you can loop over response.d and then use this code inside that outer loop.

提交回复
热议问题