LoginSignup
1
0

More than 1 year has passed since last update.

Uncaught SyntaxError: Unexpected non-whitespace character after JSON at position 3

Posted at

Uncaught SyntaxError: Unexpected non-whitespace character after JSON at position 3

JSON.parse()を使用したときのエラー

原因

  • 引数に渡った文字列がJSONの文法になっていない
json
'"{"result":{"data":[[1652040000,34361.96,34751.28,33701.01,...

サーバーサイドから渡したデータを、不必要にシングルクォーテーションで囲っていたことが原因となっていた

sample.cshtml
<script>
    const tmp = '@Html.Raw(ViewData["response"])';
    const data = JSON.parse(tmp);
</script>
1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0