我有这个值的隐藏字段我需要特别从设置字段 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>
答案 0 :(得分: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);
希望我的回答很有帮助。