我是 Json 的新手。请告诉我如何访问以下元素。这是我的 Json
var data = {"student":[{"fname":"mad", "sname":"cha"}, {"fname":"sun", "sname":"ban"}, {"fname":"sha", "sname":"kiri"}]};
所以我如何获得"mad"
价值。
实际上这就是我想做的
<html>
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<script>
function click_me(){
var data = {"student":[{"fname":"mad", "sname":"cha"}, {"fname":"sun", "sname":"ban"}, {"fname":"sha", "sname":"kiri"}]};
localStorage.setItem('my_name',data);
alert('OK');
}
function show_me(){
var x = localStorage.getItem('my_name');
x = x.student[0].fname;
alert(x);
}
</script>
</head>
<body>
<input type="button" name="btn" value="Click" onclick="click_me()">
<input type="button" name="btn" value="show_me" onclick="show_me()">
</body>
</html>