2014-11-24 3 views
0

파일은 내가 파일 및 디스플레이 "내-cluster_wait_timimg"을 읽을 수이파일에서 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." 
    } 
} 

같은 JSON 형식이 포함되어 있습니다. 그 후 , html 태그를 사용하여 위의 값을 업데이트하는 방법.

<input type=text id="" value=""/> 
+0

왜 자바 스크립트를 사용하지 않습니까? – user2360915

+0

어떻게? 이드를 사용하니? – shas

+0

문자열을 JSON 객체로로드하고 원하는 값을 업데이트 할 수 있습니다. 죄송 합니다만 질문에 충분한 정보가 없습니다. 이미 시도한 코드를 게시하십시오. – user2360915

답변

1

답이 나와 제대로 작동합니다.

<!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> 
관련 문제