Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/url/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何为json动态生成id_Javascript_Jquery_Json_Handlebars.js - Fatal编程技术网

Javascript 如何为json动态生成id

Javascript 如何为json动态生成id,javascript,jquery,json,handlebars.js,Javascript,Jquery,Json,Handlebars.js,我的json部分如下所示: { "INFO": { "01": { "Your Name": "Text" }, "02": { "Date Of Birth": "Text" }, "03": { "Married": "YesNo" }, "04": { "Gender M/

我的json部分如下所示:

 {
    "INFO": {
        "01": {
            "Your Name": "Text"
        },
        "02": {
            "Date  Of Birth": "Text"
        },
        "03": {
            "Married": "YesNo"
        },
        "04": {
            "Gender M/F": "Radiobutton"
        }
    },
    "INFO SPOUSE": {
        "01": {
            "Your Name": "Text"
        },
        "02": {
            "Date  Of Birth": "Text"
        },
        "03": {
            "Married": "YesNo"
        },
        "04": {
            "Gender M/F": "Radiobutton"
        }
    }
}
Json在前端工作正常

现在,我想为上述json为每个问题生成动态id,以便我可以将id的值用于后端目的

我想要一个基于问题编号的id,这样在后台我就可以得到这样的值(你的名字=xxx)

我使用handlebarrs.js只是为了解释(因为注释框不够)

}


如果是,则在php中实现它(只需迭代对象数组(可以使用json_decode($yourjsonstring,true)函数将其转换为plan数组),并在迭代后通过将键值分配给info和info数组中的id key来生成新数组),希望你明白我的意思。

明确你需要什么结构我需要javascript中的上述代码id。我需要javascript或jquery中的上述代码id,以便在后端我知道用户为特定问题键入的值我的意思是说,你是否在考虑这样的结构信息:{“01”:{“您的姓名”:“文本”},至信息:{“id”:“01”,“您的姓名”:“文本”},您能解释清楚吗?我无法理解我所提供的格式不需要json,如果我按照您的格式使用json,我会在前端打印id,因为我将使用“每个”和“钥匙”
my mean to say that do you like to get your JSON in the given format {
"INFO": [
    {
        "id": "1",
        "Your Name": "Text"
    },
    {
        "id": "2",
        "Date  Of Birth": "Text"
    },
    {
        "id": "3",
        "Married": "YesNo"
    },
    {
        "id": "4",
        "Gender M/F": "Radiobutton"
    }
],
"INFO SPOUSE": [
    {
        "id": "1",
        "Your Name": "Text"
    },
    {
        "id": "3",
        "Date  Of Birth": "Text"
    },
    {
        "id": "3",
        "Married": "YesNo"
    },
    {
        "id": "4",
        "Gender M/F": "Radiobutton"
    }
]