weixin_33722405 2014-03-25 18:17 采纳率: 0%
浏览 74

JSON中的JSON eval()数据

I am working with JSON and ajax. I am trying to post a value using AJAX. below is my issue:

My post value:

JSON:

{
    "employees": [{
        "firstName": "John",
        "lastName": "Doe"
    }]
}

I am posting JQuery eval() method it converts the JSON object as following:

&firstName=john&lastName=Deo

My problem comes when I try to post a JSON in side a JSON:

{
    "employees": [{
        "firstName": "John",
        "lastName": {
            "test1": "10",
            "test2": "12"
        }
    }]
}

When I use eval() method the above JSON object as follows:

&firstName=John&lastName=&test1=10&test2=12

My JQuery Code:

$.ajax({
        url: applicationURL,
        type: "POST",
        data: eval("(" + queryString + ")"),
        cache: false,
        dataType: "json",
        timeout: (60 * 10000),
        success: function (data) {
        },
        error: function (objAJAXRequest, strError) {
        }
    });

Is there any way to get the values of lastName as JSON object as above? Because eval() method coverts the lastName value also as & separate?

  • 写回答

1条回答 默认 最新

  • weixin_33691700 2014-03-25 18:22
    关注

    You should do something like:

    $.ajax({type:"POST", data: {mydata: JSON_OBJ});
    

    and then in PHP:

    $obj = json_decode($_POST["mydata"]);

    see: http://www.php.net/manual/en/function.json-decode.php

    评论

报告相同问题?

悬赏问题

  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器