//在javascript中读取json格式文件
<script type="text/javascript">
var JSONObject= {
"name":"张三",
"sex":"男",
"age":18,
"phone":"555 1234567",
"people":[{"name":"李四","age":"17"},{"name":"王五","age":"16"}]
};
//获取JSONObject name值(结果:张三)
var jsonname=JSONObject.name
//获取JSONObject sex值(结果:男)
var jsonname=JSONObject.sex
//获取JSONObject people中第一个name值(结果:李四)
var jsonname=JSONObject.people[0].name
//获取JSONObject people中第二个age值(结果:16)
var jsonname=JSONObject.people[1].age
</script>
//c#后台对json格式赋值格式
string jsons = "{\"name\":\"张三\",\"people\":[{\"name\":\"李四\",\"age\":\"18\"},{\"name\":\"王五\",\"age\":\"19\"}] }";
//javascript接收后台jsons变量时需要将string类型转换为object类型
var jsons =eval('('+ jsons+')')