I’m using jQuery to get and parse some JSON from my ASP.Net MVC backend. I’m recieving the data correctly:
data: "{"0":"Imgs/staticResistor.png","1":"Imgs/wire.png"}"
Function to get data:
$.getJSON('https://localhost:44338/Editor/GetImgUrlFromTypeID/')
.done((data) => {
console.log("JSON: " + $.parseJSON(data)[0]);
let json = $.parseJSON(data)[0];
//return $.parseJSON(data);
})
.fail((error) => {
console.log("GET request failed: " + error);
return "didnt work";
});
However, when I assign $.parseJSON(data)[0];
to a variable or return it, it’s undefined:
json: undefined
I can’t discern why the method is behaving differently in different calls.