SyntaxError: Unexpected number in JSON at position 1

版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://blog.csdn.net/ISaiSai/article/details/88420376

SyntaxError: Unexpected number in JSON at position 1

javascript JSON序列表,key 是int类型的时候,出错

处理方法,使用正则表达式,将int类型的key 替换成字符串

var a  ="{2:\"全天\",7:\"测试\",8:\"1天\",9:12,10:14}";
var x = a.replace(/(\d+):/g,"\"$1\":");
var r  = JSON.parse(x);
console.log(r["8"])
展开阅读全文

json解析格式问题 Uncaught SyntaxError: Unexpected token < in JSON at position 2

09-11

json格式解析配置也配置了 在控制器直接返回一个集合对象 在网页调试显示JSON格式错误,不知道怎么解决rn错误代码信息:rnUncaught SyntaxError: Unexpected token < in JSON at position 2rnrn请大哥们帮帮忙看一下 ,谢谢!以下是代码rnrn一、ajax请求代码rnfunction queryAround(hid) rn var user = sessionStorage.getItem("user");rn if (!user) rn window.location.href = "login.html";rn else rn $.post("/hotel/around/around/getArounds.shtml", rn hid : hidrn ,function(result1) rn var data1 = $.parseJSON(result1);rn var arr = [];rn for (var i = 0; i < data1.length; i++) rn arr.push(" "+123+"");rn arr.push(" " + data1[i].aroundName + "" + data1[i].reson + "");rn $("#arounds").html(arr.join(""));rn rn );rn rn rnrn二、控制器响应代码rn@Controllerrn@RequestMapping(value = "/around")rnpublic class AroundController extends BaseController rnrn @Autowiredrn AroundService aroundService;rnrn /**rn * 获取周边rn * rn * @returnrn */rn @RequestMapping(value = "/around/getArounds", method = RequestMethod.POST)rn @ResponseBodyrn public List getArounds(SearchVO searchVO, HttpServletRequest request, ModelMap modelMap) rn Integer hid = Integer.parseInt(request.getParameter("hid"));rn List li = aroundService.getByHid(hid);rn return li;rn rnrnrn三、spring-mvc json格式自动解析配置rnrnrn rn rn rn text/html;charset=UTF-8rn text/json;charset=UTF-8 rn application/json;charset=UTF-8 rn rn rn rnrn rn rn rn rn rn rn rn rn rn rn rn rn 论坛

Uncaught SyntaxError: Unexpected token ILLEGAL 求解!!

04-03

小菜在将一个HTML页整合到DZ论坛的时候出现了如下错误:rnrnUncaught SyntaxError: Unexpected token ILLEGALrnrn[color=#FF0000]错误行内容为: var html = ' [/color]rnrnrn以下是代码中的部分代码:rnrn[color=#0000FF] //模拟费用rnrn var showPrice = function() rnrn var price = $.trim($('.traffic .t_title input').val());rnrnrnrn //var oo = /(^d+$)|(^d+.d+$)/;rnrn //var oo = /^d+(.d+)?$/;rnrn var oo = /^(d)+$/;rnrn if (!oo.test(price) || price == '') rnrn $('.traffic .t_title input').val('');rnrn price = '';rnrn //alert("请输入正确的价格");rnrn else rnrn var frist = price.substring(0, 1);rnrn if (frist == '0') rnrn alert('基础流量费用不能少于1¥');rnrn return false;rnrn rnrn rnrn if (price.toString().length > 10) rnrn alert("费用不能超过10位数");rnrn return false;rnrn rnrnrnrn if (price == '') rnrn alert('请正确输入整数基础流量费用');rnrn return false;rnrn rnrn var input = $('#formParam input');rnrn var a = input.eq(3).val();rnrn var b = input.eq(4).val();rnrn var trafficBox = $('.traffic .trafficBox');[/color]rnrnrnrnrn [color=#FF0000] var html = ' 《===谷歌浏览器显示此行错误 rn错误信息为:Uncaught SyntaxError: Unexpected token ILLEGALrn[/color]rn [color=#0000FF] 当月流量rnrn ' + a / 1024 + 'G以下流量rnrn ' + a / 1024 + 'G-' + b + 'G流量rnrn ' + b + 'G-' + (b * 2) + 'G流量 rnrn ' + (2 * b) + 'G-' + (4 * b) + 'G流量rnrn ' + (4 * b) + 'G-' + (8 * b) + 'G流量rnrn rnrn rnrn 所需费用rnrn 免费rnrn ¥' + price + 'rnrn ¥' + (2 * price) + 'rnrn ¥' + (3 * price) + 'rnrn ¥' + (4 * price) + 'rnrn rnrn ';rnrn rnrn trafficBox.html(html);rnrn $('.traffic .attd').hide();rnrn trafficBox.show();rnrn rnrn $("#freePrice").val($("#setPrice").val());rnrn return true;rnrn [/color] 论坛

没有更多推荐了,返回首页