I would like to deal with differnet JSON-Formats.
In my first example I'am using this answering-format from PHP:
{
"errors": [ "username", "password" ]
}
$.ajax({
type: "GET",
url: "http://www.sample.com/js/l.php",
success: function(response) {
console.log(response);
var jsonResponse = JSON.parse(response);
if (jsonResponse['errors']) {
var t = "";
for (var i = 0; i < jsonResponse['errors'].length; i++) {
//works well for: {"errors":["username","password"]} ';
t = t + jsonResponse['errors'][i] + " ";
}
console.log(t);
}
}
});
The result of console is: username password
If I change the json-response to
{
"errors": {
"username": ["credentials"],
"password": ["credentials"]
}
}
I do not know how do deal with this.
The function do not work because the jsonResponse['errors'].length
is empty.
I would like to loop to username password with their values.