파일에 다음과 같은 json 형식이 포함되어 있습니다.
{
"ClusterName": {
"Description": "Name of the dbX Cluster",
"Type": "String",
"MinLength": "1",
"MaxLength": "64",
"AllowedPattern": "[-_ a-zA-Z0-9]*",
"Default": "my-cluster_wait_timimg",
"ConstraintDescription": "can contain only alphanumeric characters, spaces, dashes and underscores."
}
}
파일을 읽고 "my-cluster_wait_timimg" 표시하고 싶습니다 . 그 후 html 태그를 사용하여 위의 값을 어떻게 업데이트합니까?
<input type=text id="" value=""/>
대답을 얻었고 이것은 나를 위해 잘 작동합니다.
<!DOCTYPE html>
<html>
<body>
<h2>Create Object from JSON String</h2>
<input type="text" id="demo">
<button onclick="fun1()">Click here</button>
<script>
var text = '{"ClusterName":{ "Description": "Name of the dbX Cluster", "Type": "String", "MinLength": "1", "MaxLength": "64", "AllowedPattern": "[-_ a-zA-Z0-9]*","Default": "my-cluster_wait_timimg", "ConstraintDescription": "can contain only alphanumeric characters, spaces, dashes and underscores."}}';
obj = JSON.parse(text);
document.getElementById("demo").value =
obj.ClusterName.Default + " " ;
function fun1() {
var rs=document.getElementById("demo").value;
alert(rs);
}
</script>
</body>
</html>
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다