例1
代码如下 |
复制代码 |
JSON数据如:{"options":"[{"text":"王家湾","value":"9"},{"text":"李家湾","valu
e":"10"},{"text":"邵家湾","value":"13"}]"}
用js可以写成: JSON数据如:{"options":"[{"text":"王家湾","value":"9"},{"text":"李家湾","valu
e":"10"},{"text":"邵家湾","value":"13"}]"}
|
用js可以写成:
代码如下 |
复制代码 |
var data=[{name:"a",age:12},{name:"b",age:11},{name:"c",age:13},{name:"d",age:14}];
for(var o in data){
alert(o);
alert(data[o]);
alert("text:"+data[o].name+" value:"+data[o].age );
}
|
例2
代码如下 |
复制代码 |
<script language="javascript">
function e()
{
var json=[{"kl_id":"2","kl_title":"Test date","kl_content":"Test date","kl_type":"1","id":"1"},{"kl_id":"2","kl_title":"Test","kl_content":"Test","kl_type":"1","id":"2"}]
var str = "";
for (var one in json)
{
for(var key in json[one])
{
str += json[one][key] + ",";
}
}
document.form.txtName.value = str;
}
</script>
<form name="form">
<a href="#" onclick="e();">Click</a>
<br>
<input name="txtName" value="" type="text" size="50">
</form>
|
|