简体   繁体   中英

Ajax response and Jquery parse.JSON error

I'm consuming a Rest API. Post call for a login. Got a 200 and a lot of things said API returns. I want to console.log that data (just to confirm things, and see what info I will want to preserve). So I tried:

        $.ajax({
      url: 'http://www.mensagemassinada.com.br/QSWebAPI/API/Login',
      type: 'POST',
      data: JSON.stringify(tudo),
      contentType: 'application/json; charset=utf-8',
      dataType: 'json',
      async: false,
      complete: function(data) {
        var cap = data.responseJSON
        console.log(cap);
        console.log(data);
      },
    });

    event.preventDefault();
    })

I can get the info I want (in data.responseJSON). In the plain "data" console.log I get all other info from the server. I want to acess individual itens inside said responseJSON (in the log I can see that responseJSON is a array). How can I acess individual values inside this array? I believe I would use parseJson, but got a error, regarding JSON structure. This is the array content printscreen (with private data edited):

数组

From what I could find the Json format should be different. But I just want to confirm if the error is my fault, or if I need to ask for some modifications from the back end guy.

thanks in advance.

您可以通过定位ID为0的数组来访问数据

console.log(cap[0].Empr_Nome);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM