Why, when I load my array and try to get its length, it just splashes out the number of bytes the array is in

When I use the jQuery library to load an array and get its length using my own javascript, it just splashes out the total number of bytes of the array, for example:

$.get({
  url: 'https://rawgit.com/tvman-123/shrek/master/ExampleOutputForSubscription_Post.php', //
  data: {},
  success: function(data) {
    ParseData(data);
  }
});


function ParseData(data) {
  console.log(data.length) //Returns 221
}
<script src="https://code.jquery.com/jquery-3.1.1.min.js"></script>
Run codeHide result

But when I turn on the inline array, it works as expected, like so:

data=["UU9CuvdOVfMPvKCiwdGKL3cQ","UUrTNhL_yO3tPTdQ5XgmmWjA","UUz-RZblnhjXK_krP1jDybeQ","UUc_xdkOBgSYLmXTn-VSQ4uA","UUmb8hO2ilV9vRa8cilis88A","UU45SDrjKlPSY0bTvH6F7TOA","UUdGkmb5zEDXnPSmQlV43t0Q","UUpeGBKn0axOJAcPHkcPiXcg",""]
ParseData(data)

function ParseData(data){
console.log(data.length)//Returns 9
}
<script src="https://code.jquery.com/jquery-3.1.1.min.js"></script>
Run codeHide result

I understand that the first one is an array of bytes, and the second is an arraylist.

Can someone explain to me why this is done and how to fix it ???

EDIT:

Thanks to everyone for your answers and helped me solve this problem.

+4
source share
4 answers

- JSON! add dataType: "json"

$.get({
  url: 'https://rawgit.com/tvman-123/shrek/master/ExampleOutputForSubscription_Post.php', //
  data: {},
  dataType: "json",
  success: function(data) {
    console.log(data.length); // data is parsed.. =)
  }
});
Hide result
+1

JSON.parse, ( ).

$.get({
  url: 'https://rawgit.com/tvman-123/shrek/master/ExampleOutputForSubscription_Post.php', //
  data: {},
  success: function(data) {
    ParseData(JSON.parse(data));
  }
});


function ParseData(data) {
  console.log(data.length);
}
<script src="https://code.jquery.com/jquery-3.1.1.min.js"></script>
Hide result
+4

, ( JSON). , .

JSON . .

JSON . JSON.parse(data), .

+3

. , , - , . Array, .

, , . Array, , ( ) JSON api parse. .

0

Source: https://habr.com/ru/post/1662002/


All Articles