简体   繁体   English

SyntaxError: JSON.parse: JSON 数据的第 1 行第 1 列的数据意外结束,使用 fetch

[英]SyntaxError: JSON.parse: unexpected end of data at line 1 column 1 of the JSON data using fetch

I'm using this function我正在使用这个功能

obtenerCursos:async function(){
                    const data = await fetch('cursos.json', {mode: 'no-cors'});
                    const cursos = await data.json();
                    commit('llenarCursos',cursos)
                }

I try to get data from local json file:我尝试从本地 json 文件中获取数据:

[
    {"nombre":"item1", "id":1},
    {"nombre":"item2", "id":2},
    {"nombre":"item3", "id":3}
]

But I'm not getting json data I get a object但我没有得到 json 数据我得到了一个对象

Response
​
body: null
​
bodyUsed: false
​
headers: Headers
​
ok: false
​
redirected: false
​
status: 0
​
statusText: ""
​
type: "opaque"
​
url: ""

I'm not sure about what I'm doing wrong我不确定我做错了什么

type: "opaque"

This means that JavaScript cannot see the content of the response.这意味着 JavaScript无法看到响应的内容

Since JS can't see the content, the content it can see has zero length.由于JS看不到内容,所以它能看到的内容长度为零。 So it gets to the end of the content before finding anything that would make it valid JSON.因此,在找到任何使其成为有效 JSON 的内容之前,它会到达内容的末尾。

It is opaque because you said:它是不透明的,因为你说:

 mode: 'no-cors'

Don't do that.不要那样做。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 使用 Fetch: SyntaxError: JSON.parse: JSON 数据第 1 行第 1 列的意外字符 - Using Fetch: SyntaxError: JSON.parse: unexpected character at line 1 column 1 of the JSON data SyntaxError:JSON.parse:JSON数据的第1行第1列出现意外字符吗? - SyntaxError: JSON.parse: unexpected character at line 1 column 1 of the JSON data? 语法错误:JSON.parse:JSON 数据的第 1 行第 1 列出现意外字符 - SyntaxError: JSON.parse: unexpected character at line 1 column 1 of the JSON data 语法错误json.parse json数据第1行第1列的意外字符 - syntaxerror json.parse unexpected character at line 1 column 1 of the json data SyntaxError:JSON.parse:JSON数据第3行第1列的意外字符 - SyntaxError: JSON.parse: unexpected character at line 3 column 1 of the JSON data SyntaxError:JSON.parse:JSON数据的第1行第2列出现意外字符 - SyntaxError: JSON.parse: unexpected character at line 1 column 2 of the JSON data React SyntaxError:JSON.parse:JSON 数据第 1 行第 1 列的数据意外结束 - React SyntaxError: JSON.parse: unexpected end of data at line 1 column 1 of the JSON data SyntaxError: JSON.parse: JSON 数据第 1 行第 1 列的数据意外结束 OK - SyntaxError: JSON.parse: unexpected end of data at line 1 column 1 of the JSON data OK SyntaxError: JSON.parse: JSON 数据的第 1 行第 1 列的数据意外结束 - SyntaxError: JSON.parse: unexpected end of data at line 1 column 1 of the JSON data Javascript 错误:SyntaxError: JSON.parse: JSON 数据第 1 行第 1 列的数据意外结束 - Javascript error: SyntaxError: JSON.parse: unexpected end of data at line 1 column 1 of the JSON data
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM