How to JSON decode array elements in JavaScript?

前端 未结 7 675
盖世英雄少女心
盖世英雄少女心 2020-11-30 08:40

I have a JavaScript array that, among others, contains a URL. If I try to simply put the URL in the page (the array is in a project involving the Yahoo! Maps API) it shows t

7条回答
  •  春和景丽
    2020-11-30 09:13

    If you get this text in an alert:

    function(){return JSON.encode(this);}
    

    when you try alert(myArray[i]), then there are a few possibilities:

    • myArray[i] is a function (most likely)
    • myArray[i] is the literal string "function(){return JSON.encode(this);}"
    • myArray[i] has a .toString() method that returns that function or that string. This is the least likely of the three.

    The simplest way to tell would be to check typeof(myArray[i]).

提交回复
热议问题