0

i have this hidden fields with this values i need to get values specially from setting field id="fields[0].settings" *(value="{"x":"x"}")* pass it as json object

<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>

1 Answers1

0

in order to convert string to JSON object you should use the following JavaScript command

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

in your case you can do the following:

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

Hope my answer was helpfull.

Scription
  • 646
  • 3
  • 12
  • 21