0

我有这个值的隐藏字段我需要专门从设置字段 id="fields[0].settings" *(value="{"x":"x"}")* 将其作为 json 对象传递

<div class="fieldProperties"> 
        <input type="hidden" id="fields[0].id" name="fields[0].id" value="null">
        <input type="hidden" id="fields[0].name" name="fields[0].name" value="">
        <input type="hidden" id="fields[0].type" name="fields[0].type" value="SingleChoice">
        <input type="hidden" id="fields[0].settings" name="fields[0].settings" value="{"en":{"label":"Single Line Text 1","value":"","description":"","Choice":"","styles":{"fontFamily":"default","fontSize":"default","fontStyles":[0,0,0]}},"zh_CN":{"label":"单行文字输入 1","value":"","description":"","Choice":"ar","styles":{"fontFamily":"default","fontSize":"default","fontStyles":[0,0,0]}},"_persistable":true,"required":true,"restriction":"no","styles":{"label":{"color":"rgb(0, 0, 0)","backgroundColor":"rgba(0, 0, 0, 0)"},"value":{},"description":{"color":"777777","backgroundColor":"rgba(0, 0, 0, 0)"}}}">   
        <input type="hidden" id="fields[0].sequence" name="fields[0].sequence" value="0">
        <input type="hidden" id="fields[0].status" name="fields[0].status">
</div>
4

1 回答 1

0

为了将字符串转换为 JSON 对象,您应该使用以下 JavaScript 命令

var myString = "put here the string you want to convert to JSON in correct format";
var myJSON = JSON.parse(myString);

在您的情况下,您可以执行以下操作:

var settingValue = document.getElementById("fields[0].settings");
var settingObject = JSON.parse(settingValue);

希望我的回答对您有所帮助。

于 2013-08-12T05:19:43.670 回答