JSON.parse: unexpected character at line 1 column 1 of the JSON data (php)

后端 未结 1 394
没有蜡笔的小新
没有蜡笔的小新 2021-01-15 04:17

I am unable to access json data as it always fails and gives error as SyntaxError: JSON.parse: unexpected character at line 1 column 1 of the JSON data search.php outputs t

相关标签:
1条回答
  • 2021-01-15 04:45

    Solution for your problem is JSON.stringify

    You need to convert your data output into string i.e.,

     var yourDataStr = JSON.stringify(yourdata) 
    

    and then validate your data with

    JSON.parse(yourDataStr)
    

    Then you can get your result. To validate, you can pass your data in below function :-

    function validateJSON(str) {
        try {
           JSON.parse(str);
        } catch (e) {
         return false;
        }
      return true;
    }
    
    0 讨论(0)
提交回复
热议问题