这种JSON数据怎么解析????
[{"krnum":0,"kname":"娱乐","kid":1},{"krnum":0,"kname":"生活","kid":2},{"krnum":0,"kname"...
[{"krnum":0,"kname":"娱乐","kid":1},{"krnum":0,"kname":"生活","kid":2},{"krnum":0,"kname":"财经","kid":3},{"krnum":0,"kname":"购物","kid":4},{"krnum":0,"kname":"科技","kid":5},{"krnum":0,"kname":"健康","kid":6},{"krnum":0,"kname":"旅游","kid":7},{"krnum":0,"kname":"体育","kid":8},{"krnum":0,"kname":"军事","kid":9},{"krnum":0,"kname":"文化","kid":10},{"krnum":0,"kname":"其他","kid":11}]
展开
展开全部
json就相当于js的数组和对象的结构,你这个最外层是中括号,所以是个数组,数组的每一项是大括号包围的,所以数组每个元素是一个js的对象结构
只要用for循环遍历数组,得到每个对象
js的对象是key:value格式的。所以用 对象.key 方式获取数据的
var list = [{"krnum":0,"kname":"娱乐","kid":1},{"krnum":0,"kname":"生活","kid":2},{"krnum":0,"kname":"财经","kid":3},{"krnum":0,"kname":"购物","kid":4},{"krnum":0,"kname":"科技","kid":5},{"krnum":0,"kname":"健康","kid":6},{"krnum":0,"kname":"旅游","kid":7},{"krnum":0,"kname":"体育","kid":8},{"krnum":0,"kname":"军事","kid":9},{"krnum":0,"kname":"文化","kid":10},{"krnum":0,"kname":"其他","kid":11}];
for(var i=0;i<list.length;i++)
{
var item = list[i];
alert(item.kname)//获取kname的值
}
只要用for循环遍历数组,得到每个对象
js的对象是key:value格式的。所以用 对象.key 方式获取数据的
var list = [{"krnum":0,"kname":"娱乐","kid":1},{"krnum":0,"kname":"生活","kid":2},{"krnum":0,"kname":"财经","kid":3},{"krnum":0,"kname":"购物","kid":4},{"krnum":0,"kname":"科技","kid":5},{"krnum":0,"kname":"健康","kid":6},{"krnum":0,"kname":"旅游","kid":7},{"krnum":0,"kname":"体育","kid":8},{"krnum":0,"kname":"军事","kid":9},{"krnum":0,"kname":"文化","kid":10},{"krnum":0,"kname":"其他","kid":11}];
for(var i=0;i<list.length;i++)
{
var item = list[i];
alert(item.kname)//获取kname的值
}
展开全部
<script language="javascript">
var data = eval('[{"krnum":0,"kname":"娱乐","kid":1},{"krnum":0,"kname":"生活","kid":2},{"krnum":0,"kname":"财经","kid":3},{"krnum":0,"kname":"购物","kid":4},{"krnum":0,"kname":"科技","kid":5},{"krnum":0,"kname":"健康","kid":6},{"krnum":0,"kname":"旅游","kid":7},{"krnum":0,"kname":"体育","kid":8},{"krnum":0,"kname":"军事","kid":9},{"krnum":0,"kname":"文化","kid":10},{"krnum":0,"kname":"其他","kid":11}]');
var View = [];
for(var i=0;i<data.length;i++)
{
View.push("ID:"+data[i].krnum+" ");
View.push("Name"+data[i].kname+" ");
View.push("Kid"+data[i].kid+"\n");
}
alert(View.join(""));
</script>
var data = eval('[{"krnum":0,"kname":"娱乐","kid":1},{"krnum":0,"kname":"生活","kid":2},{"krnum":0,"kname":"财经","kid":3},{"krnum":0,"kname":"购物","kid":4},{"krnum":0,"kname":"科技","kid":5},{"krnum":0,"kname":"健康","kid":6},{"krnum":0,"kname":"旅游","kid":7},{"krnum":0,"kname":"体育","kid":8},{"krnum":0,"kname":"军事","kid":9},{"krnum":0,"kname":"文化","kid":10},{"krnum":0,"kname":"其他","kid":11}]');
var View = [];
for(var i=0;i<data.length;i++)
{
View.push("ID:"+data[i].krnum+" ");
View.push("Name"+data[i].kname+" ");
View.push("Kid"+data[i].kid+"\n");
}
alert(View.join(""));
</script>
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
要把你的json代码发上来,这样提问都不知道怎么回答的
你要追问里提问,或者做问题的补充就可以
你要追问里提问,或者做问题的补充就可以
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询