繁体   English   中英

Uncaught SyntaxError: Unexpected token : in JSON at position 362

[英]Uncaught SyntaxError: Unexpected token : in JSON at position 362

我写了一段JS代码:

window.scraping = JSON.parse('"' + tab_url + '"' + ":" + JSON.stringify(scraping));

其中tab_url是:

'"https://www.google.com/search?ei=UFd7XvKqG9DwaIauhLgB&q=integrate+discord+chat+in+atom&oq=integrate+discord+chat+in+atom&gs_l=psy-ab.3..0j0i22i30l3j0i22i10i30j0i22i30j0i22i10i30j0i22i30l3.205903.213924..214423...0.4..0.509.1961.0j1j0j1j2j1......0....1..gws-wiz.......0i71j0i67j0i131j0i131i67j0i10.DB2bC6vf4pE&ved=0ahUKEwjykr3I2LXoAhVQOBoKHQYXARcQ4dUDCAs&uact=5":{"title":"","text":"","ranking_word":{},"a":[],"img":[],"html":""}'

scraping在哪里:

var scraping = {
                "title": "",
                "text": "",
                "ranking_word": {},
                "a": [],
                "img": [],
                "html": ""
              }

代码返回一个错误:

Uncaught SyntaxError: Unexpected token : in JSON at position 362

我不明白为什么:被拒绝...

我假设您想在 tab_url 中嵌入抓取对象。

尝试运行此代码段。

 let scraping = { "title": "", "text": "", "ranking_word": {}, "a": [], "img": [], "html": "" }; let tab_url = `{"https://www.google.com/search?ei=UFd7XvKqG9DwaIauhLgB&q=integrate+discord+chat+in+atom&oq=integrate+discord+chat+in+atom&gs_l=psy-ab.3..0j0i22i30l3j0i22i10i30j0i22i30j0i22i10i30j0i22i30l3.205903.213924..214423...0.4..0.509.1961.0j1j0j1j2j1......0....1..gws-wiz.......0i71j0i67j0i131j0i131i67j0i10.DB2bC6vf4pE&ved=0ahUKEwjykr3I2LXoAhVQOBoKHQYXARcQ4dUDCAs&uact=5":${JSON.stringify(scraping)}}`; console.log(JSON.parse(tab_url));
 .as-console-wrapper { max-height: 100% !important; top: 0; }

暂无
暂无

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM