首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >为什么浏览器要在json响应中添加额外的反斜杠,同时JSON数组长度也是错误的?

为什么浏览器要在json响应中添加额外的反斜杠,同时JSON数组长度也是错误的?
EN

Stack Overflow用户
提问于 2014-10-13 10:00:03
回答 1查看 1.1K关注 0票数 1

这就是我用JSON值向服务器发出回调请求的方式

代码语言:javascript
复制
$(document).on('click', '.currentOrderRow', function(event ) {
var orderid = $(this).attr("id_data");

$.ajax({
        type: 'GET',
        url: url+'/OMS/oms1/getOrderdetails?orderid='+orderid,
        jsonpCallback: 'jsonCallback',
        cache: true,
        dataType: 'jsonp',
        jsonp: false,
        success: function (response) {
    alert(response.json_value.length);
            console.log('response is'+JSON.stringify(response));

        },
        error: function (e) {
            alert('Into error ');
        }
    });


});

当服务器控制台中显示的JSON响应在in ()中有斜杠时,我进行了观察

代码语言:javascript
复制
{
    "json_value": "[{\"contact_phone_no\":\"9876543210\",\"SurCharges\":\"50\",\"vendorname\":\"VC4 Raj\",\"contact_email\":\"rajk@gmail.com\",\"count\":\"0\",\"discount_div\":\"10%\",\"itemid\":\"188\",\"strikeprice_cutoff\":\"90\",\"name\":\"Popcorn Plain salted\",\"contact_address\":\"Kukatpally, Hyderabad\",\"quantity\":\"1\",\"email_id\":\"raj@hmail.com\",\"date_time\":\"14:10:37\",\"toppings\":[{\"name\":\"Quantity  1\",\"value\":[\"Honey with Chocolate Sauce 10 ML\",\"None\",\"None\",\"None\",\"None\",\"None\",\"None\",\"None\"]}],\"screen\":\"SCR-3\",\"seat_num\":\"D12\",\"customer_name\":\"Ganesh\",\"image\":\"images/icon-print.png\",\"contact_person\":\"Kiran\",\"item_description\":\"Item description\",\"vendor_id\":\"9\",\"crusts\":[],\"Vat\":\"70\",\"customer_mobil\":\"9090987878\",\"price\":\"115\",\"mobile_number\":\"1234567898\",\"ServicesCharges\":\"50\",\"orderid\":\"14101337\"},{\"contact_phone_no\":\"9876543210\",\"SurCharges\":\"50\",\"vendorname\":\"VC4 Raj\",\"contact_email\":\"rajk@gmail.com\",\"count\":\"0\",\"discount_div\":\"10Rs\",\"itemid\":\"194\",\"strikeprice_cutoff\":\"110\",\"name\":\"Popcorn Regular   300 ML Fountain Apple\",\"contact_address\":\"Kukatpally, Hyderabad\",\"quantity\":\"1\",\"email_id\":\"raj@hmail.com\",\"date_time\":\"14:10:37\",\"toppings\":[{\"name\":\"Quantity  1\",\"value\":[\"Chocolate\",\"Vanila\"]}],\"screen\":\"SCR-3\",\"seat_num\":\"D12\",\"customer_name\":\"Ganesh\",\"image\":\"images/icon-print.png\",\"contact_person\":\"Kiran\",\"item_description\":\"Item description\",\"vendor_id\":\"9\",\"crusts\":[{\"name\":\"Quantity  1\",\"value\":[\"Butter scotch\"]}],\"Vat\":\"70\",\"customer_mobil\":\"9090987878\",\"price\":\"275\",\"mobile_number\":\"1234567898\",\"ServicesCharges\":\"50\",\"orderid\":\"14101337\"}]"
}

为什么长度显示为1525?

因为上面的JSON由其中的两个值组成??(从contact_phone_no开始,每个记录都是一个新记录)

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2014-10-13 10:07:11

服务器端有一个bug。它没有向您发送JSON对象图(即嵌套JSON对象),而是向您发送包含JSON格式对象的单个字符串。或者换一种方式:它将JSON发送到JSON中。

要解析数据,需要以下代码:

代码语言:javascript
复制
var data = JSON.parse(response.json_value);

或者修复服务器端的错误。

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/26337290

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档