tonyliang_id
2016-07-04 16:05
采纳率: 54.8%
浏览 8.1k
已采纳

如何在JS 中获取 JSON 对象中某个域的值

问题:如何在JS中获取"内省与专注"对应的score值?
基本情况:
1)JSON 格式化链接
2)JSON 内容

 {"data":[{"id":{"domain":"内省与专注","userName":"guest"},"score":35},{"id":{"domain":"创造力向度指标","userName":"guest"},"score":34},{"id":{"domain":"学校满意度","userName":"guest"},"score":33},{"id":{"domain":"学校激活度","userName":"guest"},"score":35},{"id":{"domain":"学生综合自评分","userName":"guest"},"score":34},{"id":{"domain":"应用向度指标","userName":"guest"},"score":37},{"id":{"domain":"数理逻辑思维","userName":"guest"},"score":37},{"id":{"domain":"沟通与交往","userName":"guest"},"score":34},{"id":{"domain":"理解与表达","userName":"guest"},"score":37},{"id":{"domain":"空间与建构","userName":"guest"},"score":31},{"id":{"domain":"综合动觉协调","userName":"guest"},"score":34},{"id":{"domain":"综合音乐素养","userName":"guest"},"score":33},{"id":{"domain":"观察与实践","userName":"guest"},"score":39},{"id":{"domain":"认知向度指标","userName":"guest"},"score":37},{"id":{"domain":"评价向度指标","userName":"guest"},"score":31}],"success":"true"}
  • 写回答
  • 好问题 提建议
  • 关注问题
  • 收藏
  • 邀请回答

3条回答 默认 最新

  • tonyliang_id 2016-07-05 13:56
    已采纳
     {"data":[{"domain":"沟通与交往","score":39,"userName":"guest"},{"domain":"观察与实践","score":38,"userName":"guest"},{"domain":"综合音乐素养","score":37,"userName":"guest"},{"domain":"综合动觉协调","score":37,"userName":"guest"},{"domain":"内省与专注","score":35,"userName":"guest"},{"domain":"数理逻辑思维","score":34,"userName":"guest"},{"domain":"空间与建构","score":32,"userName":"guest"},{"domain":"理解与表达","score":32,"userName":"guest"}],"success":"true"}
    
         var obj;
        var url = "talent/summaryBar";
        var params = {
                username:"guest",
            };  
    
        $.ajax({ 
            type : "get", 
            url : url, 
            data : params, 
            async : false, 
            success : function(data){
                    obj = data;
                    /* var str = JSON.stringify( data );
                    alert(str);*/
                    alert(data.data[0].domain); 
                } 
            });
    
    已采纳该答案
    评论
    解决 无用
    打赏 举报
  • 毕小宝 2016-07-05 00:42

    首先,可以用js的转成JSON对象,JSON.parse(jsonstr);
    然后,就是解析这个json对象的data属性,是一个List,遍历整个list每一个元素,获取id的domain值,如果是内省与专注,取该元素的score值啊。
    就是读取js的对象的属性的过程的。

    评论
    解决 无用
    打赏 举报
  • 评论
    解决 无用
    打赏 举报

相关推荐 更多相似问题